diff --git a/cli_tool_framework/interfaces/cli_tool/src/cli_tool_mgr_client.cpp b/cli_tool_framework/interfaces/cli_tool/src/cli_tool_mgr_client.cpp index 6ffb348f3d..adce485895 100644 --- a/cli_tool_framework/interfaces/cli_tool/src/cli_tool_mgr_client.cpp +++ b/cli_tool_framework/interfaces/cli_tool/src/cli_tool_mgr_client.cpp @@ -191,7 +191,11 @@ ErrCode CliToolMGRClient::BatchRegisterFunctions(const std::vector return GET_CLI_TOOL_MGR_SERVICE_FAILED; } FunctionsRawData rawData; - FunctionsRawData::FromFunctionInfoVec(functions, rawData); + int32_t ret = FunctionsRawData::FromFunctionInfoVec(functions, rawData); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "FromFunctionInfoVec failed: %{public}d", ret); + return ret; + } return proxy->BatchRegisterFunctions(rawData, successCount); } diff --git a/cli_tool_framework/interfaces/cli_tool/src/tool_info.cpp b/cli_tool_framework/interfaces/cli_tool/src/tool_info.cpp index 6be9d01122..dcebb7b86c 100644 --- a/cli_tool_framework/interfaces/cli_tool/src/tool_info.cpp +++ b/cli_tool_framework/interfaces/cli_tool/src/tool_info.cpp @@ -20,6 +20,7 @@ #include #include "hilog_tag_wrapper.h" +#include "raw_data_utils.h" #include "securec.h" namespace OHOS { @@ -496,12 +497,20 @@ void ToolsRawData::FromToolInfoVec(const std::vector &tools, ToolsRawD int32_t ToolsRawData::ToToolInfoVec(const ToolsRawData &rawData, std::vector &tools) { + if (rawData.data == nullptr || rawData.size == 0) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "ToToolInfoVec failed: null data or zero size"); + return ERR_INVALID_VALUE; + } std::stringstream ss; ss.write(reinterpret_cast(rawData.data), rawData.size); ss.seekg(0, std::ios::beg); uint32_t ssLength = static_cast(ss.str().length()); + uint32_t count = 0; - ss.read(reinterpret_cast(&count), sizeof(count)); + if (!ReadRaw(ss, &count, sizeof(count))) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "Failed to read count, stream state invalid"); + return ERR_INVALID_VALUE; + } if (count > MAX_TOOL_INFO_COUNT) { TAG_LOGE(AAFwkTag::CLI_TOOL, "tools exceed maxSize %{public}d, count: %{public}d", MAX_TOOL_INFO_COUNT, count); @@ -509,22 +518,10 @@ int32_t ToolsRawData::ToToolInfoVec(const ToolsRawData &rawData, std::vector(&toolSize), sizeof(toolSize)); - if (toolSize > ssLength - static_cast(ss.tellg())) { - TAG_LOGE(AAFwkTag::CLI_TOOL, "toolSize:%{public}u is invalid", toolSize); - return ERR_INVALID_VALUE; - } - std::string toolStr(toolSize, '\0'); - ss.read(toolStr.data(), toolSize); - nlohmann::json jsonObject = nlohmann::json::parse(toolStr, nullptr, false, true); - if (jsonObject.is_discarded()) { - TAG_LOGE(AAFwkTag::CLI_TOOL, "json parse failed, index: %{public}u", i); - return ERR_INVALID_VALUE; - } - if (!ToolInfo::ParseFromJson(jsonObject, tools[i])) { - TAG_LOGE(AAFwkTag::CLI_TOOL, "ParseFromJson failed, index: %{public}u", i); - return ERR_INVALID_VALUE; + int32_t ret = ReadOneItem(ss, ssLength, tools[i], true, ERR_INVALID_VALUE); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "ReadOneItem failed, index: %{public}u, ret: %{public}d", i, ret); + return ret; } } return ERR_OK; diff --git a/cli_tool_framework/interfaces/function/BUILD.gn b/cli_tool_framework/interfaces/function/BUILD.gn index 4f42104c76..a84c660954 100644 --- a/cli_tool_framework/interfaces/function/BUILD.gn +++ b/cli_tool_framework/interfaces/function/BUILD.gn @@ -41,6 +41,7 @@ ohos_source_set("function_info") { sources = [ "src/function_info.cpp", + "src/raw_data_utils.cpp", ] external_deps = [ diff --git a/cli_tool_framework/interfaces/function/include/function_info.h b/cli_tool_framework/interfaces/function/include/function_info.h index ffbb07a724..ee9eba6c42 100644 --- a/cli_tool_framework/interfaces/function/include/function_info.h +++ b/cli_tool_framework/interfaces/function/include/function_info.h @@ -86,8 +86,9 @@ public: * @brief Convert vector of FunctionInfo to FunctionsRawData * @param functions Input vector of FunctionInfo * @param rawData Output FunctionsRawData + * @return int32_t ERR_OK on success, ERR_INVALID_VALUE if count exceeds the maximum */ - static void FromFunctionInfoVec(const std::vector &functions, FunctionsRawData &rawData); + static int32_t FromFunctionInfoVec(const std::vector &functions, FunctionsRawData &rawData); /** * @brief Convert FunctionsRawData to vector of FunctionInfo diff --git a/cli_tool_framework/interfaces/function/include/raw_data_utils.h b/cli_tool_framework/interfaces/function/include/raw_data_utils.h new file mode 100644 index 0000000000..cc2d50dae2 --- /dev/null +++ b/cli_tool_framework/interfaces/function/include/raw_data_utils.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2026 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"), + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ABILITY_RUNTIME_RAW_DATA_UTILS_H +#define OHOS_ABILITY_RUNTIME_RAW_DATA_UTILS_H + +#include +#include +#include + +#include + +#include "cli_error_code.h" +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace CliTool { + +// Read exactly len bytes into buf; returns false if the stream enters a failed state. +inline bool ReadRaw(std::stringstream &ss, void *buf, std::streamsize len) +{ + ss.read(reinterpret_cast(buf), len); + return static_cast(ss); +} + +int32_t ReadItemToJson(std::stringstream &ss, uint32_t ssLength, bool allowComments, + int32_t parseFailCode, nlohmann::json &out); + +template +int32_t ReadOneItem(std::stringstream &ss, uint32_t ssLength, T &out, + bool allowComments, int32_t parseFailCode) +{ + nlohmann::json j; + int32_t ret = ReadItemToJson(ss, ssLength, allowComments, parseFailCode, j); + if (ret != ERR_OK) { + return ret; + } + if (!T::ParseFromJson(j, out)) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "Failed to parse item from JSON"); + return parseFailCode; + } + return ERR_OK; +} + +} // namespace CliTool +} // namespace OHOS + +#endif // OHOS_ABILITY_RUNTIME_RAW_DATA_UTILS_H diff --git a/cli_tool_framework/interfaces/function/src/function_info.cpp b/cli_tool_framework/interfaces/function/src/function_info.cpp index 14367c0b67..a5b99790a1 100644 --- a/cli_tool_framework/interfaces/function/src/function_info.cpp +++ b/cli_tool_framework/interfaces/function/src/function_info.cpp @@ -15,6 +15,7 @@ #include "function_info.h" +#include #include #include #include @@ -23,9 +24,12 @@ #include "cli_error_code.h" #include "hilog_tag_wrapper.h" +#include "raw_data_utils.h" namespace { -constexpr uint32_t MAX_FUNCTION_INFO_COUNT = 10000; // Maximum number of functions in single transfer +constexpr uint32_t MAX_FUNCTION_INFO_COUNT = 200 * 1000; // Maximum number of function info (200 * 1000) +constexpr uint32_t MAX_SCHEMA_STRING_LENGTH = 16 * 1024; // Maximum length of inputSchema/outputSchema (16KB) +constexpr uint32_t MAX_RAW_DATA_SIZE = 128 * 1024 * 1024; // Shared memory cap for FunctionsRawData (128MB) } namespace OHOS { @@ -56,6 +60,11 @@ bool ParseInputSchema(const nlohmann::json &json, std::string &output) if (inputSchema.is_string()) { output = inputSchema.get(); if (!output.empty()) { + if (output.size() > MAX_SCHEMA_STRING_LENGTH) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "ParseFromJson failed: inputSchema too long: %{public}u, max: %{public}u", + static_cast(output.size()), MAX_SCHEMA_STRING_LENGTH); + return false; + } nlohmann::json parsed = nlohmann::json::parse(output, nullptr, false); if (parsed.is_discarded()) { TAG_LOGE(AAFwkTag::CLI_TOOL, "ParseFromJson failed: inputSchema is not valid JSON"); @@ -77,6 +86,12 @@ bool ParseOutputSchema(const nlohmann::json &json, std::string &output) if (outputSchema.is_string()) { output = outputSchema.get(); if (!output.empty()) { + if (output.size() > MAX_SCHEMA_STRING_LENGTH) { + TAG_LOGE(AAFwkTag::CLI_TOOL, + "ParseFromJson failed: outputSchema too long: %{public}u, max: %{public}u", + static_cast(output.size()), MAX_SCHEMA_STRING_LENGTH); + return false; + } nlohmann::json parsed = nlohmann::json::parse(output, nullptr, false); if (parsed.is_discarded()) { TAG_LOGE(AAFwkTag::CLI_TOOL, "ParseFromJson failed: outputSchema is not valid JSON"); @@ -100,14 +115,24 @@ bool ParseFunctionType(const nlohmann::json &json, FunctionType &output) TAG_LOGE(AAFwkTag::CLI_TOOL, "Invalid functionType type in JSON, must be integer"); return false; } - int32_t typeValue = functionType.get(); - if (typeValue >= 0 && typeValue < static_cast(FunctionType::END)) { - output = static_cast(typeValue); + if (functionType.is_number_unsigned()) { + auto val = functionType.get(); + if (val >= static_cast(FunctionType::END)) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "Invalid functionType value: %{public}llu, out of range [0, %{public}d)", + static_cast(val), static_cast(FunctionType::END)); + return false; + } + output = static_cast(val); return true; } - TAG_LOGE(AAFwkTag::CLI_TOOL, "Invalid functionType value: %{public}d, out of range [0, %{public}d)", - typeValue, static_cast(FunctionType::END)); - return false; + auto val = functionType.get(); + if (val < 0 || val >= static_cast(FunctionType::END)) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "Invalid functionType value: %{public}lld, out of range [0, %{public}d)", + static_cast(val), static_cast(FunctionType::END)); + return false; + } + output = static_cast(val); + return true; } } // namespace @@ -236,6 +261,11 @@ bool FunctionInfo::Validate(const FunctionInfo &function) } if (!function.inputSchema.empty()) { + if (function.inputSchema.size() > MAX_SCHEMA_STRING_LENGTH) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "Validate failed: inputSchema too long: %{public}u, max: %{public}u", + static_cast(function.inputSchema.size()), MAX_SCHEMA_STRING_LENGTH); + return false; + } nlohmann::json inputSchemaJson = nlohmann::json::parse(function.inputSchema, nullptr, false); if (inputSchemaJson.is_discarded()) { TAG_LOGE(AAFwkTag::CLI_TOOL, "Validate failed: inputSchema is not valid JSON"); @@ -244,6 +274,11 @@ bool FunctionInfo::Validate(const FunctionInfo &function) } if (!function.outputSchema.empty()) { + if (function.outputSchema.size() > MAX_SCHEMA_STRING_LENGTH) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "Validate failed: outputSchema too long: %{public}u, max: %{public}u", + static_cast(function.outputSchema.size()), MAX_SCHEMA_STRING_LENGTH); + return false; + } nlohmann::json outputSchemaJson = nlohmann::json::parse(function.outputSchema, nullptr, false); if (outputSchemaJson.is_discarded()) { TAG_LOGE(AAFwkTag::CLI_TOOL, "Validate failed: outputSchema is not valid JSON"); @@ -271,6 +306,10 @@ int32_t FunctionsRawData::RawDataCpy(const void *readdata) TAG_LOGE(AAFwkTag::CLI_TOOL, "null data or zero size"); return ERR_INVALID_VALUE; } + if (size > MAX_RAW_DATA_SIZE) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "raw data size too large: %{public}u, max: %{public}u", size, MAX_RAW_DATA_SIZE); + return ERR_INVALID_VALUE; + } void* newData = malloc(size); if (newData == nullptr) { TAG_LOGE(AAFwkTag::CLI_TOOL, "malloc failed"); @@ -290,8 +329,13 @@ int32_t FunctionsRawData::RawDataCpy(const void *readdata) return ERR_OK; } -void FunctionsRawData::FromFunctionInfoVec(const std::vector &functions, FunctionsRawData &rawData) +int32_t FunctionsRawData::FromFunctionInfoVec(const std::vector &functions, FunctionsRawData &rawData) { + if (functions.size() > MAX_FUNCTION_INFO_COUNT) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "FromFunctionInfoVec exceed max count %{public}u, count: %{public}zu", + MAX_FUNCTION_INFO_COUNT, functions.size()); + return ERR_INVALID_VALUE; + } std::stringstream ss; uint32_t count = functions.size(); ss.write(reinterpret_cast(&count), sizeof(count)); @@ -307,16 +351,25 @@ void FunctionsRawData::FromFunctionInfoVec(const std::vector &func rawData.data = rawData.ownedData.data(); rawData.size = rawData.ownedData.size(); rawData.isMalloc = false; + return ERR_OK; } int32_t FunctionsRawData::ToFunctionInfoVec(const FunctionsRawData &rawData, std::vector &functions) { + if (rawData.data == nullptr || rawData.size == 0) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "ToFunctionInfoVec failed: null data or zero size"); + return ERR_INVALID_VALUE; + } std::stringstream ss; ss.write(reinterpret_cast(rawData.data), rawData.size); ss.seekg(0, std::ios::beg); uint32_t ssLength = static_cast(ss.str().length()); + uint32_t count = 0; - ss.read(reinterpret_cast(&count), sizeof(count)); + if (!ReadRaw(ss, &count, sizeof(count))) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "Failed to read count, stream state invalid"); + return ERR_INVALID_VALUE; + } if (count > MAX_FUNCTION_INFO_COUNT) { TAG_LOGE(AAFwkTag::CLI_TOOL, "functions exceed maxSize %{public}d, count: %{public}d", MAX_FUNCTION_INFO_COUNT, count); @@ -324,22 +377,10 @@ int32_t FunctionsRawData::ToFunctionInfoVec(const FunctionsRawData &rawData, std } functions.resize(count); for (uint32_t i = 0; i < count; ++i) { - uint32_t functionSize = 0; - ss.read(reinterpret_cast(&functionSize), sizeof(functionSize)); - if (functionSize > ssLength - static_cast(ss.tellg())) { - TAG_LOGE(AAFwkTag::CLI_TOOL, "functionSize:%{public}u is invalid", functionSize); - return ERR_INVALID_VALUE; - } - std::string functionStr(functionSize, '\0'); - ss.read(functionStr.data(), functionSize); - nlohmann::json j = nlohmann::json::parse(functionStr, nullptr, false); - if (j.is_discarded()) { - TAG_LOGE(AAFwkTag::CLI_TOOL, "Failed to parse JSON for function %{public}d", i); - return ERR_JSON_PARSE_FAILED; - } - if (!FunctionInfo::ParseFromJson(j, functions[i])) { - TAG_LOGE(AAFwkTag::CLI_TOOL, "Failed to parse FunctionInfo from JSON for function %{public}d", i); - return ERR_JSON_PARSE_FAILED; + int32_t ret = ReadOneItem(ss, ssLength, functions[i], false, ERR_JSON_PARSE_FAILED); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "ReadOneItem failed, index: %{public}u, ret: %{public}d", i, ret); + return ret; } } return ERR_OK; diff --git a/cli_tool_framework/interfaces/function/src/raw_data_utils.cpp b/cli_tool_framework/interfaces/function/src/raw_data_utils.cpp new file mode 100644 index 0000000000..ae1c4fd06c --- /dev/null +++ b/cli_tool_framework/interfaces/function/src/raw_data_utils.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2026 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"), + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "raw_data_utils.h" + +#include +#include + +#include + +#include "cli_error_code.h" +#include "hilog_tag_wrapper.h" + +namespace OHOS { +namespace CliTool { + +// Read a length-prefixed JSON item from the stream and parse it into out. +int32_t ReadItemToJson(std::stringstream &ss, uint32_t ssLength, bool allowComments, + int32_t parseFailCode, nlohmann::json &out) +{ + uint32_t itemSize = 0; + if (!ReadRaw(ss, &itemSize, sizeof(itemSize))) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "Failed to read item size, stream state invalid"); + return ERR_INVALID_VALUE; + } + std::streamoff curPos = ss.tellg(); + std::streamoff total = static_cast(ssLength); + if (curPos < 0 || curPos > total || itemSize > total - curPos) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "itemSize:%{public}u is invalid", itemSize); + return ERR_INVALID_VALUE; + } + std::string itemStr(itemSize, '\0'); + if (!ReadRaw(ss, itemStr.data(), itemSize)) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "Failed to read item data, stream state invalid"); + return ERR_INVALID_VALUE; + } + out = nlohmann::json::parse(itemStr, nullptr, false, allowComments); + if (out.is_discarded()) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "Failed to parse JSON"); + return parseFailCode; + } + return ERR_OK; +} + +} // namespace CliTool +} // namespace OHOS diff --git a/cli_tool_framework/services/climgr/src/cli_function_data_manager.cpp b/cli_tool_framework/services/climgr/src/cli_function_data_manager.cpp index 32741bf173..dd9e4a3aee 100644 --- a/cli_tool_framework/services/climgr/src/cli_function_data_manager.cpp +++ b/cli_tool_framework/services/climgr/src/cli_function_data_manager.cpp @@ -101,6 +101,7 @@ int32_t CliFunctionDataManager::EnsureFunctionsInitialized() return ERR_OK; } + std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { TAG_LOGE(AAFwkTag::CLI_TOOL, "KVStore not ready for functions initialization"); return ERR_NO_INIT; diff --git a/cli_tool_framework/services/climgr/src/cli_tool_manager_service.cpp b/cli_tool_framework/services/climgr/src/cli_tool_manager_service.cpp index b4bee66537..fdff41a6af 100644 --- a/cli_tool_framework/services/climgr/src/cli_tool_manager_service.cpp +++ b/cli_tool_framework/services/climgr/src/cli_tool_manager_service.cpp @@ -780,7 +780,11 @@ int32_t CliToolManagerService::GetAllFunctions(FunctionsRawData &functions) return ret; } - FunctionsRawData::FromFunctionInfoVec(functionList, functions); + ret = FunctionsRawData::FromFunctionInfoVec(functionList, functions); + if (ret != ERR_OK) { + TAG_LOGE(AAFwkTag::CLI_TOOL, "FromFunctionInfoVec failed: %{public}d", ret); + return ret; + } TAG_LOGI(AAFwkTag::CLI_TOOL, "Successfully got all functions (raw): %{public}zu", functionList.size()); return ERR_OK; } diff --git a/cli_tool_framework/test/unittest/function_info_test/function_info_test.cpp b/cli_tool_framework/test/unittest/function_info_test/function_info_test.cpp index 4653e3dcfc..c7f9a0767c 100644 --- a/cli_tool_framework/test/unittest/function_info_test/function_info_test.cpp +++ b/cli_tool_framework/test/unittest/function_info_test/function_info_test.cpp @@ -817,6 +817,62 @@ HWTEST_F(FunctionInfoTest, FunctionInfo_ParseFromJson_1600, TestSize.Level1) TAG_LOGI(AAFwkTag::TEST, "FunctionInfo_ParseFromJson_1600 end"); } +/** + * @tc.name: FunctionInfo_ParseFromJson_1700 + * @tc.desc: Test ParseFromJson with functionType exceeding INT64_MAX (number_unsigned storage). A naive + * get() would throw out_of_range and crash the process; this guards the branch. + * @tc.type: FUNC + */ +HWTEST_F(FunctionInfoTest, FunctionInfo_ParseFromJson_1700, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "FunctionInfo_ParseFromJson_1700 start"); + + // INT64_MAX + 1: parsed into number_unsigned storage, so is_number_integer() is true but + // get() would throw. Must be rejected, not crash. + nlohmann::json json = R"({ + "functionName": "overflowType", + "functionNamespace": "com.test.overflow", + "functionType": 9223372036854775808, + "version": "1.0.0", + "description": "" + })"_json; + + FunctionInfo function; + bool result = FunctionInfo::ParseFromJson(json, function); + + EXPECT_FALSE(result); + + TAG_LOGI(AAFwkTag::TEST, "FunctionInfo_ParseFromJson_1700 end"); +} + +/** + * @tc.name: FunctionInfo_ParseFromJson_1800 + * @tc.desc: Test ParseFromJson with functionType exceeding INT32_MAX but within INT64 range + * (number_integer storage). The original get() would throw out_of_range and crash. + * @tc.type: FUNC + */ +HWTEST_F(FunctionInfoTest, FunctionInfo_ParseFromJson_1800, TestSize.Level1) +{ + TAG_LOGI(AAFwkTag::TEST, "FunctionInfo_ParseFromJson_1800 start"); + + // 9999999999 > INT32_MAX but < INT64_MAX: stored as number_integer. get() would throw; + // must be rejected after reading the full-precision value. + nlohmann::json json = R"({ + "functionName": "int32Overflow", + "functionNamespace": "com.test.int32overflow", + "functionType": 9999999999, + "version": "1.0.0", + "description": "" + })"_json; + + FunctionInfo function; + bool result = FunctionInfo::ParseFromJson(json, function); + + EXPECT_FALSE(result); + + TAG_LOGI(AAFwkTag::TEST, "FunctionInfo_ParseFromJson_1800 end"); +} + // ==================== ParseToJson Tests ==================== /** diff --git a/interfaces/inner_api/ability_manager/include/auto_startup_info.h b/interfaces/inner_api/ability_manager/include/auto_startup_info.h index e3f9236b9b..64c6f0fa7e 100644 --- a/interfaces/inner_api/ability_manager/include/auto_startup_info.h +++ b/interfaces/inner_api/ability_manager/include/auto_startup_info.h @@ -30,6 +30,7 @@ enum class AutoStartupSetterType : int32_t { UNSPECIFIED = -1, SYSTEM = 0, USER = 1, + MAX }; /** diff --git a/interfaces/inner_api/ability_manager/include/exit_reason.h b/interfaces/inner_api/ability_manager/include/exit_reason.h index ed29156ee5..c58e8b1d85 100644 --- a/interfaces/inner_api/ability_manager/include/exit_reason.h +++ b/interfaces/inner_api/ability_manager/include/exit_reason.h @@ -50,12 +50,11 @@ struct ExitReasonCompability : public Parcelable { Reason reason = Reason::REASON_UNKNOWN; std::string exitMsg = ""; int32_t subReason = -1; - bool shouldKillForeground = true; - bool shouldSkipKillInStartup = false; - int32_t killId = -1; std::string killMsg = ""; std::string innerMsg = ""; + bool shouldKillForeground = true; + bool shouldSkipKillInStartup = false; bool ReadFromParcel(Parcel &parcel); virtual bool Marshalling(Parcel &parcel) const override; diff --git a/interfaces/inner_api/ability_manager/include/keep_alive_info.h b/interfaces/inner_api/ability_manager/include/keep_alive_info.h index 4d75851b4a..e758b03d18 100644 --- a/interfaces/inner_api/ability_manager/include/keep_alive_info.h +++ b/interfaces/inner_api/ability_manager/include/keep_alive_info.h @@ -30,6 +30,7 @@ enum class KeepAliveSetter : int32_t { UNSPECIFIED = -1, SYSTEM = 0, USER = 1, + MAX }; /** @@ -40,6 +41,7 @@ enum class KeepAliveAppType : int32_t { UNSPECIFIED = 0, THIRD_PARTY = 1, SYSTEM = 2, + MAX }; /** @@ -50,6 +52,7 @@ enum class KeepAlivePolicy : int32_t { UNSPECIFIED = 0, NOT_ALLOW_CANCEL = 1, ALLOW_CANCEL = 2, + MAX }; /** @@ -71,9 +74,9 @@ public: }; struct KeepAliveStatus { - int32_t code; - int32_t setterId; - KeepAliveSetter setter; + int32_t code = -1; + int32_t setterId = -1; + KeepAliveSetter setter = KeepAliveSetter::UNSPECIFIED; KeepAlivePolicy policy = KeepAlivePolicy::UNSPECIFIED; }; } // namespace AbilityRuntime diff --git a/interfaces/inner_api/ability_manager/src/ability_manager_client_c.cpp b/interfaces/inner_api/ability_manager/src/ability_manager_client_c.cpp index 94a0131426..42877139f8 100644 --- a/interfaces/inner_api/ability_manager/src/ability_manager_client_c.cpp +++ b/interfaces/inner_api/ability_manager/src/ability_manager_client_c.cpp @@ -39,6 +39,10 @@ int RecordAppExitReason(int exitReason, const char *exitMsg) int RecordAppWithReason(int pid, int uid, int exitReason, int killId, const char *exitMsg) { + if (exitReason < static_cast(OHOS::AAFwk::Reason::REASON_MIN) || + exitReason > static_cast(OHOS::AAFwk::Reason::REASON_MAX)) { + return -1; + } OHOS::AAFwk::Reason reason = static_cast(exitReason); std::string exitMsgStr = (exitMsg != nullptr) ? std::string(exitMsg) : std::string(); OHOS::AAFwk::ExitReasonCompability exitReasonData = { reason, exitMsgStr }; diff --git a/services/abilitymgr/include/keep_alive/keep_alive_process_manager.h b/services/abilitymgr/include/keep_alive/keep_alive_process_manager.h index 12afcded7c..a67d7cd957 100644 --- a/services/abilitymgr/include/keep_alive/keep_alive_process_manager.h +++ b/services/abilitymgr/include/keep_alive/keep_alive_process_manager.h @@ -38,6 +38,13 @@ struct KeepAliveAbilityInfo { std::string abilityName; }; +struct KeepAliveRetryContext { + KeepAliveAbilityInfo info; + uint32_t accessTokenId = -1; + bool isMultiInstance = false; + int triedCount = 0; +}; + class CheckStatusBarTask { public: CheckStatusBarTask() = delete; @@ -157,7 +164,7 @@ public: int32_t ClearKeepAliveAppServiceExtension(int32_t userId); - void SaveAppSeriviceRestartAfterUpgrade(const std::string &bundleName, int32_t uid); + void SaveAppServiceRestartAfterUpgrade(const std::string &bundleName, int32_t uid); void SaveKeepAliveAppRestartAfterUpgrade(const std::string &bundleName, int32_t uid); @@ -182,10 +189,11 @@ private: bool IsRunningAppInStatusBar(const AppExecFwk::BundleInfo &bundleInfo); void StartKeepAliveAppServiceExtensionPerBundle(const AppExecFwk::BundleInfo &bundleInfo); int32_t StartKeepAliveAppServiceExtensionInner(const KeepAliveAbilityInfo &info); + void ScheduleRetryTask(std::shared_ptr context); ffrt::mutex checkStatusBarTasksMutex_; std::vector> checkStatusBarTasks_; - std::mutex restartAfterUpgradeMutex_; + ffrt::mutex restartAfterUpgradeMutex_; std::set restartAfterUpgradeList_; std::set keepAliveRestartAfterUpgradeList_; diff --git a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp index d0bb0e2118..acf50801d9 100644 --- a/services/abilitymgr/src/ability_auto_startup_data_manager.cpp +++ b/services/abilitymgr/src/ability_auto_startup_data_manager.cpp @@ -130,29 +130,22 @@ int32_t AbilityAutoStartupDataManager::InsertAutoStartupData( info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str(), info.setterUserId, info.userId, static_cast(info.setterType)); - { - std::lock_guard lock(kvStorePtrMutex_); - if (!CheckKvStore()) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null kvStore"); - return ERR_NO_INIT; - } - } DistributedKv::Key key = ConvertAutoStartupDataToKey(info); DistributedKv::Value value = ConvertAutoStartupStatusToValue(info, isAutoStartup, isEdmForce); DistributedKv::Status status; { std::lock_guard lock(kvStorePtrMutex_); - status = kvStorePtr_->Put(key, value); - } - - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore insert error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); - status = RestoreKvStore(status); + if (!CheckKvStore()) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null kvStore"); + return ERR_NO_INIT; + } + status = kvStorePtr_->Put(key, value); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore insert error: %{public}d", status); + status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } dbWriteCounter_.UpdateWriteCount(AUTO_STARTUP_STORAGE_DIR); return ERR_OK; @@ -173,40 +166,27 @@ int32_t AbilityAutoStartupDataManager::UpdateAutoStartupData(const AutoStartupIn info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str(), info.setterUserId, info.userId, static_cast(info.setterType)); + DistributedKv::Key key = ConvertAutoStartupDataToKey(info); + DistributedKv::Value value = ConvertAutoStartupStatusToValue(info, isAutoStartup, isEdmForce); + DistributedKv::Status status; { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null kvStore"); return ERR_NO_INIT; } - } - - DistributedKv::Key key = ConvertAutoStartupDataToKey(info); - DistributedKv::Status status; - { - std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->Delete(originKey); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore delete error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore delete error: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; - } - DistributedKv::Value value = ConvertAutoStartupStatusToValue(info, isAutoStartup, isEdmForce); - { - std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->Put(key, value); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore insert error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore insert error: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } dbWriteCounter_.UpdateWriteCount(AUTO_STARTUP_STORAGE_DIR); @@ -226,27 +206,20 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const AutoStartupIn " accessTokenId: %{public}s, userId:%{public}d", info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str(), info.userId); + + DistributedKv::Status status; { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null kvStore"); return ERR_NO_INIT; } - } - - DistributedKv::Status status; - { - std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->Delete(originKey); - } - - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore delete error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore delete error: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } return ERR_OK; } @@ -261,27 +234,21 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string & TAG_LOGD(AAFwkTag::AUTO_STARTUP, "bundleName: %{public}s, accessTokenId: %{public}s", bundleName.c_str(), accessTokenIdStr.c_str()); + + std::vector allEntries; + DistributedKv::Status status; { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null kvStore"); return ERR_NO_INIT; } - } - - std::vector allEntries; - DistributedKv::Status status = DistributedKv::Status::SUCCESS; - { - std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->GetEntries(nullptr, allEntries); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetEntries error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetEntries error: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } for (const auto &item : allEntries) { @@ -289,14 +256,11 @@ int32_t AbilityAutoStartupDataManager::DeleteAutoStartupData(const std::string & { std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->Delete(item.key); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore delete error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "kvStore delete error: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } } } @@ -319,6 +283,9 @@ AutoStartupStatus AbilityAutoStartupDataManager::QueryAutoStartupData(const Auto " accessTokenId: %{public}s, userId: %{public}d", info.bundleName.c_str(), info.moduleName.c_str(), info.abilityName.c_str(), info.accessTokenId.c_str(), info.userId); + + std::vector allEntries; + DistributedKv::Status status; { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -326,22 +293,13 @@ AutoStartupStatus AbilityAutoStartupDataManager::QueryAutoStartupData(const Auto startupStatus.code = ERR_NO_INIT; return startupStatus; } - } - - std::vector allEntries; - DistributedKv::Status status = DistributedKv::Status::SUCCESS; - { - std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->GetEntries(nullptr, allEntries); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetEntries error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetEntries error: %{public}d", status); status = RestoreKvStore(status); + startupStatus.code = ERR_INVALID_OPERATION; + return startupStatus; } - startupStatus.code = ERR_INVALID_OPERATION; - return startupStatus; } startupStatus.code = ERR_NAME_NOT_FOUND; @@ -361,27 +319,21 @@ int32_t AbilityAutoStartupDataManager::QueryAllAutoStartupApplications(std::vect int32_t userId, bool isCalledByEDM) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called"); + + std::vector allEntries; + DistributedKv::Status status; { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null kvStore"); return ERR_NO_INIT; } - } - - std::vector allEntries; - DistributedKv::Status status = DistributedKv::Status::SUCCESS; - { - std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->GetEntries(nullptr, allEntries); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetEntries: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetEntries: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } for (const auto &item : allEntries) { @@ -402,27 +354,21 @@ int32_t AbilityAutoStartupDataManager::GetCurrentAppAutoStartupData( const std::string &bundleName, std::vector &infoList, const std::string &accessTokenId) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called"); + + std::vector allEntries; + DistributedKv::Status status; { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null kvStore"); return ERR_NO_INIT; } - } - - std::vector allEntries; - DistributedKv::Status status = DistributedKv::Status::SUCCESS; - { - std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->GetEntries(nullptr, allEntries); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetEntries error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetEntries error: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } for (const auto &item : allEntries) { @@ -501,8 +447,14 @@ void AbilityAutoStartupDataManager::ConvertAutoStartupStatusFromValue( startupStatus.setterUserId = jsonObject.at(JSON_KEY_SETTER_USERID).get(); } if (jsonObject.contains(JSON_KEY_SETTER_TYPE) && jsonObject[JSON_KEY_SETTER_TYPE].is_number()) { - startupStatus.setterType = - static_cast(jsonObject.at(JSON_KEY_SETTER_TYPE).get()); + int32_t setterTypeValue = jsonObject.at(JSON_KEY_SETTER_TYPE).get(); + if (setterTypeValue < static_cast(AutoStartupSetterType::UNSPECIFIED) || + setterTypeValue >= static_cast(AutoStartupSetterType::MAX)) { + TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Invalid setterType: %{public}d, using UNSPECIFIED", setterTypeValue); + startupStatus.setterType = AutoStartupSetterType::UNSPECIFIED; + } else { + startupStatus.setterType = static_cast(setterTypeValue); + } } if (jsonObject.contains(JSON_KEY_IS_HIDDEN_START) && jsonObject[JSON_KEY_IS_HIDDEN_START].is_boolean()) { startupStatus.isHiddenStart = jsonObject.at(JSON_KEY_IS_HIDDEN_START).get(); diff --git a/services/abilitymgr/src/ability_auto_startup_service.cpp b/services/abilitymgr/src/ability_auto_startup_service.cpp index d19f600c18..caa9a2db28 100644 --- a/services/abilitymgr/src/ability_auto_startup_service.cpp +++ b/services/abilitymgr/src/ability_auto_startup_service.cpp @@ -43,7 +43,26 @@ constexpr const char* HIDDEN_START_AUTOSTARTUP = "hiddenStartAutoStartup"; AbilityAutoStartupService::AbilityAutoStartupService() {} -AbilityAutoStartupService::~AbilityAutoStartupService() {} +AbilityAutoStartupService::~AbilityAutoStartupService() +{ + { + std::lock_guard deathLock(deathRecipientsMutex_); + for (auto &entry : deathRecipients_) { + if (entry.first != nullptr && entry.second != nullptr) { + wptr weakCallback = entry.first; + auto callback = weakCallback.promote(); + if (callback != nullptr) { + callback->RemoveDeathRecipient(entry.second); + } + } + } + deathRecipients_.clear(); + } + { + std::lock_guard lock(autoStartUpMutex_); + callbackVector_.clear(); + } +} int32_t AbilityAutoStartupService::RegisterAutoStartupSystemCallback(const sptr &callback) { @@ -81,9 +100,9 @@ int32_t AbilityAutoStartupService::UnregisterAutoStartupSystemCallback(const spt return code; } + bool isFound = false; { std::lock_guard lock(autoStartUpMutex_); - bool isFound = false; auto item = callbackVector_.begin(); while (item != callbackVector_.end()) { if (*item == callback) { @@ -97,6 +116,16 @@ int32_t AbilityAutoStartupService::UnregisterAutoStartupSystemCallback(const spt TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Callback not exist"); } } + + // Clean up death recipients if callback was found and is not null + if (isFound && callback != nullptr) { + std::lock_guard deathLock(deathRecipientsMutex_); + auto iter = deathRecipients_.find(callback); + if (iter != deathRecipients_.end()) { + callback->RemoveDeathRecipient(iter->second); + deathRecipients_.erase(iter); + } + } return ERR_OK; } @@ -443,7 +472,7 @@ std::string AbilityAutoStartupService::GetSelfApplicationBundleName() bool AbilityAutoStartupService::CheckSelfApplication(const std::string &bundleName) { TAG_LOGD(AAFwkTag::AUTO_STARTUP, "Called, bundleName: %{public}s", bundleName.c_str()); - return GetSelfApplicationBundleName() == bundleName ? true : false; + return GetSelfApplicationBundleName() == bundleName; } int32_t AbilityAutoStartupService::GetValidUserId(int32_t userId) diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index f325e8e359..9792e8dcf2 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -2030,7 +2030,7 @@ ErrCode AbilityManagerClient::KillProcessWithPrepareTerminate(const std::vector< ErrCode AbilityManagerClient::KillProcessWithReason(int32_t pid, const ExitReason &reason) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "kill pid:%{public}d, reason:%{public}d, subReason:%{public}d, exitMsg:%{public}s", + TAG_LOGI(AAFwkTag::ABILITYMGR, "kill pid:%{public}d, reason:%{public}d, subReason:%{public}d, exitMsg:%{public}s", pid, reason.reason, reason.subReason, reason.exitMsg.c_str()); auto abms = GetAbilityManager(); CHECK_POINTER_RETURN_NOT_CONNECTED(abms); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 9b58a15a22..9588bc2d42 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -3749,7 +3749,7 @@ void AbilityManagerService::AppUpgradeCompleted(int32_t uid, int32_t installType KeepAliveType type = KeepAliveType::UNSPECIFIED; if (!KeepAliveUtils::IsKeepAliveBundle(bundleInfo, userId, type)) { - TAG_LOGW(AAFwkTag::ABILITYMGR, "not keep-alive application uid: %{public}d", uid); + TAG_LOGW(AAFwkTag::ABILITYMGR, "not keep-alive application. uid: %{public}d", uid); return; } @@ -3899,6 +3899,8 @@ int32_t AbilityManagerService::KillAppWithReason(const int32_t pid, const ExitRe return ERR_PERMISSION_DENIED; } ExitReason reason(exitReason.reason, exitReason.subReason, exitReason.exitMsg); + reason.shouldKillForeground = exitReason.shouldKillForeground; + reason.shouldSkipKillInStartup = exitReason.shouldSkipKillInStartup; bool isKillPrecedeStart = (exitReason.reason == Reason::REASON_RESOURCE_CONTROL && exitReason.exitMsg == GlobalConstant::LOW_MEMORY_KILL) || exitReason.shouldSkipKillInStartup; auto innerRet = KillAppWithReasonInner(pid, reason, isKillPrecedeStart, exitReason.shouldKillForeground); @@ -9456,7 +9458,7 @@ void AbilityManagerService::HandleAppUpgradeProcess(const std::string &bundleNam IN_PROCESS_CALL_WITHOUT_RET( KeepAliveProcessManager::GetInstance().SaveKeepAliveAppRestartAfterUpgrade(bundleName, uid)); IN_PROCESS_CALL_WITHOUT_RET( - KeepAliveProcessManager::GetInstance().SaveAppSeriviceRestartAfterUpgrade(bundleName, uid)); + KeepAliveProcessManager::GetInstance().SaveAppServiceRestartAfterUpgrade(bundleName, uid)); } int AbilityManagerService::PreLoadAppDataAbilities(const std::string &bundleName, const int32_t userId) @@ -14368,7 +14370,7 @@ int32_t AbilityManagerService::KillProcessWithReason(int32_t pid, const ExitReas } #endif auto ret = KillProcessWithReasonInner(pid, reason, isKillPrecedeStart); - TAG_LOGE(AAFwkTag::ABILITYMGR, "KillProcessWithReason pid:%{public}d,ret:%{public}d,reason:%{public}s", pid, ret, + TAG_LOGI(AAFwkTag::ABILITYMGR, "KillProcessWithReason pid:%{public}d,ret:%{public}d,reason:%{public}s", pid, ret, reason.exitMsg.c_str()); if (isKillPrecedeStart) { AbilityEventUtil::SendKillProcessWithReasonEvent(ret, "KillProcessWithReason", eventInfo); @@ -16295,6 +16297,9 @@ void AbilityManagerService::RecordAppRestartExitReason(bool isAppRecovery, int32 int32_t killId = HiviewDFX::ProcessKillReason::KillEventId::REASON_RESTART; AAFwk::ExitReasonCompability exitReason(killId); auto result = IN_PROCESS_CALL(RecordAppWithReason(callerPid, callerUid, exitReason)); + if (result != ERR_OK) { + TAG_LOGW(AAFwkTag::ABILITYMGR, "RecordAppRestartExitReason failed, result: %{public}d", result); + } } int32_t AbilityManagerService::RestartApp(const AAFwk::Want &want, bool isAppRecovery) diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 2634183812..ce4534b0c0 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -2114,7 +2114,7 @@ int AbilityManagerStub::CloseUIAbilityBySCBInner(MessageParcel &data, MessagePar int AbilityManagerStub::GetWantSenderInner(MessageParcel &data, MessageParcel &reply) { if (AAFwk::AppUtils::GetInstance().IsForbidStart()) { - TAG_LOGW(AAFwkTag::APPMGR, "forbid start: GetWantSenderInner"); + TAG_LOGW(AAFwkTag::WANTAGENT, "forbid start: GetWantSenderInner"); return AAFwk::INNER_ERR; } std::unique_ptr wantSenderInfo(data.ReadParcelable()); @@ -4004,7 +4004,7 @@ int32_t AbilityManagerStub::KillProcessWithReasonInner(MessageParcel &data, Mess int32_t pid = data.ReadInt32(); std::unique_ptr reason(data.ReadParcelable()); if (reason == nullptr) { - TAG_LOGE(AAFwkTag::APPMGR, "reason null"); + TAG_LOGE(AAFwkTag::ABILITYMGR, "reason null"); return ERR_INVALID_VALUE; } int32_t result = KillProcessWithReason(pid, *reason); diff --git a/services/abilitymgr/src/app_exit_reason_helper.cpp b/services/abilitymgr/src/app_exit_reason_helper.cpp index f97f989ab0..725f2df292 100644 --- a/services/abilitymgr/src/app_exit_reason_helper.cpp +++ b/services/abilitymgr/src/app_exit_reason_helper.cpp @@ -80,7 +80,8 @@ int32_t AppExitReasonHelper::RecordAppWithReasonInner(const ExitReasonCompabilit int32_t extensionResultCode = RecordProcessExtensionExitReason( processInfo.pid_, bundleName, exitReason, processInfo, false); if (extensionResultCode != ERR_OK) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "not record extension reason: %{public}d", extensionResultCode); + TAG_LOGW(AAFwkTag::ABILITYMGR, "record extension reason failed. bundleName: %{public}s, ret: %{public}d", + bundleName.c_str(), extensionResultCode); } int32_t ret = DelayedSingleton::GetInstance()->NotifyAppMgrRecordExitReasonCompability( @@ -145,6 +146,10 @@ int32_t AppExitReasonHelper::RecordAppExitReason(const ExitReason &exitReason) int32_t userId = -1; int32_t getOsAccountRet = AppExecFwk::OsAccountManagerWrapper:: GetOsAccountLocalIdFromUid(uid, userId); + if (getOsAccountRet != ERR_OK) { + TAG_LOGE(AAFwkTag::ABILITYMGR, "get GetOsAccountLocalIdFromUid failed. ret: %{public}d", getOsAccountRet); + return getOsAccountRet; + } GetRunningProcessInfo(pid, userId, bundleName, processInfo); int32_t resultCode = RecordProcessExtensionExitReason(pid, bundleName, exitReason, processInfo, false); if (resultCode != ERR_OK) { @@ -164,10 +169,6 @@ int32_t AppExitReasonHelper::RecordAppExitReason(const ExitReason &exitReason) TAG_LOGE(AAFwkTag::ABILITYMGR, "abilityLists empty"); return ERR_GET_ACTIVE_ABILITY_LIST_EMPTY; } - if (getOsAccountRet != ERR_OK) { - TAG_LOGE(AAFwkTag::ABILITYMGR, "get GetOsAccountLocalIdFromUid failed. ret: %{public}d", getOsAccountRet); - return ERR_INVALID_VALUE; - } TAG_LOGD(AAFwkTag::ABILITYMGR, "userId: %{public}d, bundleName: %{public}s, appIndex: %{public}d", userId, bundleName.c_str(), appIndex); uint32_t accessTokenId = Security::AccessToken::AccessTokenKit::GetHapTokenID(userId, bundleName, appIndex); diff --git a/services/abilitymgr/src/dialog_session/dialog_session_manager.cpp b/services/abilitymgr/src/dialog_session/dialog_session_manager.cpp index 80edf325ec..f94d8cf99e 100644 --- a/services/abilitymgr/src/dialog_session/dialog_session_manager.cpp +++ b/services/abilitymgr/src/dialog_session/dialog_session_manager.cpp @@ -579,7 +579,7 @@ bool DialogSessionManager::IsCreateCloneSelectorDialog(const std::string &bundle return false; #else if (StartAbilityUtils::isWantWithAppCloneIndex || StartAbilityUtils::isSandBoxClone) { - TAG_LOGI(AAFwkTag::ABILITYMGR, "no clone index"); + TAG_LOGI(AAFwkTag::ABILITYMGR, "with clone index"); StartAbilityUtils::isWantWithAppCloneIndex = false; return false; } diff --git a/services/abilitymgr/src/keep_alive/ability_keep_alive_data_manager.cpp b/services/abilitymgr/src/keep_alive/ability_keep_alive_data_manager.cpp index c09d56d692..3f5615bd62 100644 --- a/services/abilitymgr/src/keep_alive/ability_keep_alive_data_manager.cpp +++ b/services/abilitymgr/src/keep_alive/ability_keep_alive_data_manager.cpp @@ -33,6 +33,32 @@ const std::string JSON_KEY_APP_TYPE = "appType"; const std::string JSON_KEY_SETTER = "setter"; const std::string JSON_KEY_SETTERID = "setterId"; const std::string JSON_KEY_POLICY = "policy"; + +/** + * @brief Parse and validate enum value from JSON object. + * @tparam EnumType The enum type with UNSPECIFIED as lower bound and MAX as upper sentinel. + * @param jsonObject The JSON object to parse from. + * @param key The JSON key to read. + * @param defaultValue The default value if validation fails. + * @param fieldName The field name for error logging. + * @return The parsed and validated enum value. + */ +template +EnumType ParseEnum(const nlohmann::json &jsonObject, const std::string &key, + EnumType defaultValue, const std::string &fieldName) +{ + if (!jsonObject.contains(key) || !jsonObject[key].is_number()) { + return defaultValue; + } + + int32_t value = jsonObject.at(key).get(); + if (value < static_cast(EnumType::UNSPECIFIED) || + value >= static_cast(EnumType::MAX)) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "Invalid %{public}s: %{public}d", fieldName.c_str(), value); + return defaultValue; + } + return static_cast(value); +} } // namespace const DistributedKv::AppId AbilityKeepAliveDataManager::APP_ID = { "keep_alive_storage" }; const DistributedKv::StoreId AbilityKeepAliveDataManager::STORE_ID = { "keep_alive_infos" }; @@ -50,6 +76,7 @@ AbilityKeepAliveDataManager::~AbilityKeepAliveDataManager() std::lock_guard lock(kvStorePtrMutex_); if (kvStorePtr_ != nullptr) { dataManager_.CloseKvStore(APP_ID, kvStorePtr_); + kvStorePtr_ = nullptr; } } @@ -128,30 +155,24 @@ int32_t AbilityKeepAliveDataManager::InsertKeepAliveData(const KeepAliveInfo &in TAG_LOGD(AAFwkTag::KEEP_ALIVE, "bundleName: %{public}s, userId: %{public}d, appType: %{public}d, setter: %{public}d", - info.bundleName.c_str(), info.userId, info.appType, info.setter); - { - std::lock_guard lock(kvStorePtrMutex_); - if (!CheckKvStore()) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null kvStore"); - return ERR_NO_INIT; - } - } + info.bundleName.c_str(), info.userId, static_cast(info.appType), + static_cast(info.setter)); DistributedKv::Key key = ConvertKeepAliveDataToKey(info); DistributedKv::Value value = ConvertKeepAliveStatusToValue(info); DistributedKv::Status status; { std::lock_guard lock(kvStorePtrMutex_); - status = kvStorePtr_->Put(key, value); - } - - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "kvStore insert error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); - status = RestoreKvStore(status); + if (!CheckKvStore()) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null kvStore"); + return ERR_NO_INIT; + } + status = kvStorePtr_->Put(key, value); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "kvStore insert error: %{public}d", status); + status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } return ERR_OK; } @@ -165,28 +186,23 @@ int32_t AbilityKeepAliveDataManager::DeleteKeepAliveData(const KeepAliveInfo &in TAG_LOGD(AAFwkTag::KEEP_ALIVE, "bundleName: %{public}s, userId: %{public}d, appType: %{public}d, setter: %{public}d", - info.bundleName.c_str(), info.userId, info.appType, info.setter); + info.bundleName.c_str(), info.userId, static_cast(info.appType), + static_cast(info.setter)); + + std::vector allEntries; + DistributedKv::Status status = DistributedKv::Status::SUCCESS; { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null kvStore"); return ERR_NO_INIT; } - } - - std::vector allEntries; - DistributedKv::Status status = DistributedKv::Status::SUCCESS; - { - std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->GetEntries(nullptr, allEntries); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "GetEntries error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "GetEntries error: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } for (const auto &item : allEntries) { @@ -194,14 +210,11 @@ int32_t AbilityKeepAliveDataManager::DeleteKeepAliveData(const KeepAliveInfo &in { std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->Delete(item.key); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "kvStore delete error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "kvStore delete error: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } } } @@ -220,6 +233,9 @@ KeepAliveStatus AbilityKeepAliveDataManager::QueryKeepAliveData(const KeepAliveI TAG_LOGD(AAFwkTag::KEEP_ALIVE, "bundleName: %{public}s, userId: %{public}d", info.bundleName.c_str(), info.userId); + + std::vector allEntries; + DistributedKv::Status status = DistributedKv::Status::SUCCESS; { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { @@ -227,22 +243,13 @@ KeepAliveStatus AbilityKeepAliveDataManager::QueryKeepAliveData(const KeepAliveI kaStatus.code = ERR_NO_INIT; return kaStatus; } - } - - std::vector allEntries; - DistributedKv::Status status = DistributedKv::Status::SUCCESS; - { - std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->GetEntries(nullptr, allEntries); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "GetEntries error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "GetEntries error: %{public}d", status); status = RestoreKvStore(status); + kaStatus.code = ERR_INVALID_OPERATION; + return kaStatus; } - kaStatus.code = ERR_INVALID_OPERATION; - return kaStatus; } kaStatus.code = ERR_NAME_NOT_FOUND; @@ -267,28 +274,23 @@ int32_t AbilityKeepAliveDataManager::QueryKeepAliveApplications( TAG_LOGD(AAFwkTag::KEEP_ALIVE, "bundleName: %{public}s, userId: %{public}d, appType: %{public}d, setter: %{public}d", - queryParam.bundleName.c_str(), queryParam.userId, queryParam.appType, queryParam.setter); + queryParam.bundleName.c_str(), queryParam.userId, static_cast(queryParam.appType), + static_cast(queryParam.setter)); + + std::vector allEntries; + DistributedKv::Status status = DistributedKv::Status::SUCCESS; { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null kvStore"); return ERR_NO_INIT; } - } - - std::vector allEntries; - DistributedKv::Status status = DistributedKv::Status::SUCCESS; - { - std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->GetEntries(nullptr, allEntries); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "GetEntries: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "GetEntries: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } for (const auto &item : allEntries) { @@ -304,27 +306,21 @@ int32_t AbilityKeepAliveDataManager::QueryKeepAliveApplications( int32_t AbilityKeepAliveDataManager::DeleteKeepAliveDataWithSetterId(const KeepAliveInfo &info) { TAG_LOGD(AAFwkTag::KEEP_ALIVE, "setterId: %{public}d", info.setterId); + + std::vector allEntries; + DistributedKv::Status status = DistributedKv::Status::SUCCESS; { std::lock_guard lock(kvStorePtrMutex_); if (!CheckKvStore()) { TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null kvStore"); return ERR_NO_INIT; } - } - - std::vector allEntries; - DistributedKv::Status status = DistributedKv::Status::SUCCESS; - { - std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->GetEntries(nullptr, allEntries); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "GetEntries error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "GetEntries error: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } for (const auto &item : allEntries) { @@ -332,14 +328,11 @@ int32_t AbilityKeepAliveDataManager::DeleteKeepAliveDataWithSetterId(const KeepA { std::lock_guard lock(kvStorePtrMutex_); status = kvStorePtr_->Delete(item.key); - } - if (status != DistributedKv::Status::SUCCESS) { - TAG_LOGE(AAFwkTag::KEEP_ALIVE, "kvStore delete error: %{public}d", status); - { - std::lock_guard lock(kvStorePtrMutex_); + if (status != DistributedKv::Status::SUCCESS) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "kvStore delete error: %{public}d", status); status = RestoreKvStore(status); + return ERR_INVALID_OPERATION; } - return ERR_INVALID_OPERATION; } } } @@ -368,15 +361,16 @@ void AbilityKeepAliveDataManager::ConvertKeepAliveStatusFromValue(const Distribu TAG_LOGE(AAFwkTag::KEEP_ALIVE, "parse jsonObject fail"); return; } - if (jsonObject.contains(JSON_KEY_SETTER) && jsonObject[JSON_KEY_SETTER].is_number()) { - status.setter = KeepAliveSetter(jsonObject.at(JSON_KEY_SETTER).get()); - } + + status.setter = ParseEnum(jsonObject, JSON_KEY_SETTER, + KeepAliveSetter::UNSPECIFIED, "setter"); + if (jsonObject.contains(JSON_KEY_SETTERID) && jsonObject[JSON_KEY_SETTERID].is_number()) { status.setterId = jsonObject.at(JSON_KEY_SETTERID).get(); } - if (jsonObject.contains(JSON_KEY_POLICY) && jsonObject[JSON_KEY_POLICY].is_number()) { - status.policy = KeepAlivePolicy(jsonObject.at(JSON_KEY_POLICY).get()); - } + + status.policy = ParseEnum(jsonObject, JSON_KEY_POLICY, + KeepAlivePolicy::UNSPECIFIED, "policy"); } DistributedKv::Key AbilityKeepAliveDataManager::ConvertKeepAliveDataToKey(const KeepAliveInfo &info) @@ -411,22 +405,17 @@ KeepAliveInfo AbilityKeepAliveDataManager::ConvertKeepAliveInfoFromKey(const Dis info.userId = jsonObject.at(JSON_KEY_USERID).get(); } - if (jsonObject.contains(JSON_KEY_APP_TYPE) && jsonObject[JSON_KEY_APP_TYPE].is_number()) { - info.appType = KeepAliveAppType(jsonObject.at(JSON_KEY_APP_TYPE).get()); - } - - if (jsonObject.contains(JSON_KEY_SETTER) && jsonObject[JSON_KEY_SETTER].is_number()) { - info.setter = KeepAliveSetter(jsonObject.at(JSON_KEY_SETTER).get()); - } + info.appType = ParseEnum(jsonObject, JSON_KEY_APP_TYPE, + KeepAliveAppType::UNSPECIFIED, "appType"); + info.setter = ParseEnum(jsonObject, JSON_KEY_SETTER, + KeepAliveSetter::UNSPECIFIED, "setter"); + info.policy = ParseEnum(jsonObject, JSON_KEY_POLICY, + KeepAlivePolicy::UNSPECIFIED, "policy"); if (jsonObject.contains(JSON_KEY_SETTERID) && jsonObject[JSON_KEY_SETTERID].is_number()) { info.setterId = jsonObject.at(JSON_KEY_SETTERID).get(); } - if (jsonObject.contains(JSON_KEY_POLICY) && jsonObject[JSON_KEY_POLICY].is_number()) { - info.policy = KeepAlivePolicy(jsonObject.at(JSON_KEY_POLICY).get()); - } - return info; } diff --git a/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp b/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp index 4e28e6d637..383b7a3b3d 100644 --- a/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp +++ b/services/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp @@ -60,6 +60,7 @@ int32_t AbilityKeepAliveService::SetKeepAliveTrue(const KeepAliveInfo &info) return AbilityKeepAliveDataManager::GetInstance().InsertKeepAliveData(info); } + // check if the app is already set by a higher priority setter if (static_cast(status.setter) <= static_cast(info.setter)) { TAG_LOGI(AAFwkTag::KEEP_ALIVE, "app is already set"); return ERR_OK; @@ -105,10 +106,7 @@ void AbilityKeepAliveService::GetValidUserId(int32_t &userId) if (userId >= 0) { return; } - - if (userId < 0) { - userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); - } + userId = AbilityRuntime::UserController::GetInstance().GetCallerUserId(); } bool AbilityKeepAliveService::IsKeepAliveApp(const std::string &bundleName, int32_t userId) diff --git a/services/abilitymgr/src/keep_alive/keep_alive_info.cpp b/services/abilitymgr/src/keep_alive/keep_alive_info.cpp index 89320bb59b..bff834bd35 100644 --- a/services/abilitymgr/src/keep_alive/keep_alive_info.cpp +++ b/services/abilitymgr/src/keep_alive/keep_alive_info.cpp @@ -19,14 +19,39 @@ namespace OHOS { namespace AbilityRuntime { +namespace { +/** + * @brief Validate and convert int32_t value to enum type. + * @tparam EnumType The enum type with UNSPECIFIED as lower bound and MAX as upper sentinel. + * @param value The int32_t value to convert. + * @param defaultValue The default value if validation fails. + * @param fieldName The field name for error logging. + * @return The validated enum value. + */ +template +EnumType ValidateEnum(int32_t value, EnumType defaultValue, const char *fieldName) +{ + if (value < static_cast(EnumType::UNSPECIFIED) || + value >= static_cast(EnumType::MAX)) { + TAG_LOGE(AAFwkTag::KEEP_ALIVE, "Invalid %{public}s: %{public}d", fieldName, value); + return defaultValue; + } + return static_cast(value); +} +} // namespace bool KeepAliveInfo::ReadFromParcel(Parcel &parcel) { bundleName = Str16ToStr8(parcel.ReadString16()); userId = parcel.ReadInt32(); - appType = KeepAliveAppType(parcel.ReadInt32()); - setter = KeepAliveSetter(parcel.ReadInt32()); + + appType = ValidateEnum(parcel.ReadInt32(), + KeepAliveAppType::UNSPECIFIED, "appType"); + setter = ValidateEnum(parcel.ReadInt32(), + KeepAliveSetter::UNSPECIFIED, "setter"); setterId = parcel.ReadInt32(); - policy = KeepAlivePolicy(parcel.ReadInt32()); + policy = ValidateEnum(parcel.ReadInt32(), + KeepAlivePolicy::UNSPECIFIED, "policy"); + return true; } diff --git a/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp b/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp index d58cc8622e..08e6b8a88b 100644 --- a/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp +++ b/services/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp @@ -111,21 +111,35 @@ void KeepAliveProcessManager::StartKeepAliveProcessWithMainElementPerBundle(cons } TAG_LOGE(AAFwkTag::KEEP_ALIVE, "StartKeepAliveMainAbility failed:%{public}d, retry", ret); - ffrt::submit([bundleName = bundleInfo.name, accessTokenId = bundleInfo.applicationInfo.accessTokenId, - uid = bundleInfo.uid, userId, info, ret, isMultiInstance]() mutable { - for (int tried = 0; tried < MAX_RETRY_TIMES && ret != ERR_OK; tried++) { - usleep(RETRY_INTERVAL_MICRO_SECONDS); - TAG_LOGI(AAFwkTag::KEEP_ALIVE, "retry attempt:%{public}d", tried + 1); - ret = KeepAliveProcessManager::GetInstance().StartKeepAliveMainAbility(info); - TAG_LOGI(AAFwkTag::KEEP_ALIVE, "retry result:%{public}d", ret); - } + auto context = std::make_shared(); + context->info = info; + context->accessTokenId = bundleInfo.applicationInfo.accessTokenId; + context->isMultiInstance = isMultiInstance; + context->triedCount = 0; + ScheduleRetryTask(context); +} + +void KeepAliveProcessManager::ScheduleRetryTask(std::shared_ptr context) +{ + if (context->triedCount >= MAX_RETRY_TIMES) { + TAG_LOGW(AAFwkTag::KEEP_ALIVE, "reach max retry times, failed"); + return; + } + + ffrt::task_attr attr; + attr.delay(RETRY_INTERVAL_MICRO_SECONDS); + ffrt::submit([context]() mutable { + TAG_LOGI(AAFwkTag::KEEP_ALIVE, "retry attempt:%{public}d", context->triedCount + 1); + auto ret = KeepAliveProcessManager::GetInstance().StartKeepAliveMainAbility(context->info); + TAG_LOGI(AAFwkTag::KEEP_ALIVE, "retry result:%{public}d", ret); if (ret != ERR_OK) { - TAG_LOGW(AAFwkTag::KEEP_ALIVE, "reach max retry, failed:%{public}d", ret); + context->triedCount++; + KeepAliveProcessManager::GetInstance().ScheduleRetryTask(context); return; } - KeepAliveProcessManager::GetInstance().AfterStartKeepAliveApp(bundleName, accessTokenId, uid, userId, - isMultiInstance); - }); + KeepAliveProcessManager::GetInstance().AfterStartKeepAliveApp(context->info.bundleName, + context->accessTokenId, context->info.uid, context->info.userId, context->isMultiInstance); + }, attr); } int32_t KeepAliveProcessManager::StartKeepAliveMainAbility(const KeepAliveAbilityInfo &info) @@ -405,7 +419,7 @@ int32_t KeepAliveProcessManager::SetAppServiceExtensionKeepAlive(const std::stri CHECK_RET_RETURN_RET(result, "permission denied"); CHECK_TRUE_RETURN_RET(bundleName.empty(), INVALID_PARAMETERS_ERR, "input parameter error"); - + auto bms = AbilityUtil::GetBundleManagerHelper(); CHECK_POINTER_AND_RETURN(bms, INNER_ERR); AppExecFwk::BundleInfo bundleInfo; @@ -550,7 +564,7 @@ int32_t KeepAliveProcessManager::CheckPermissionForEDM() return CHECK_PERMISSION_FAILED; } -void KeepAliveProcessManager::SaveAppSeriviceRestartAfterUpgrade(const std::string &bundleName, int32_t uid) +void KeepAliveProcessManager::SaveAppServiceRestartAfterUpgrade(const std::string &bundleName, int32_t uid) { if (!IsKeepAliveBundle(bundleName, U1_USER_ID)) { TAG_LOGE(AAFwkTag::KEEP_ALIVE, "bundle is not set keep-alive"); @@ -570,7 +584,7 @@ void KeepAliveProcessManager::SaveAppSeriviceRestartAfterUpgrade(const std::stri return; } - std::lock_guard lock(restartAfterUpgradeMutex_); + std::lock_guard lock(restartAfterUpgradeMutex_); for (const auto& info : infos) { if (info.uid_ == uid && info.isKeepAliveAppService) { restartAfterUpgradeList_.insert(uid); @@ -599,7 +613,7 @@ void KeepAliveProcessManager::SaveKeepAliveAppRestartAfterUpgrade(const std::str } if (isRunning) { - std::lock_guard lock(restartAfterUpgradeMutex_); + std::lock_guard lock(restartAfterUpgradeMutex_); TAG_LOGI(AAFwkTag::KEEP_ALIVE, "keepAliveApp is running while update. uid: %{public}d", uid); keepAliveRestartAfterUpgradeList_.insert(uid); } @@ -607,7 +621,7 @@ void KeepAliveProcessManager::SaveKeepAliveAppRestartAfterUpgrade(const std::str bool KeepAliveProcessManager::CheckNeedRestartAfterUpgrade(int32_t uid) { - std::lock_guard lock(restartAfterUpgradeMutex_); + std::lock_guard lock(restartAfterUpgradeMutex_); auto iter = restartAfterUpgradeList_.find(uid); if (iter == restartAfterUpgradeList_.end()) { return false; @@ -619,7 +633,7 @@ bool KeepAliveProcessManager::CheckNeedRestartAfterUpgrade(int32_t uid) bool KeepAliveProcessManager::KeepAliveCheckNeedRestartAfterUpgrade(int32_t uid) { - std::lock_guard lock(restartAfterUpgradeMutex_); + std::lock_guard lock(restartAfterUpgradeMutex_); auto iter = keepAliveRestartAfterUpgradeList_.find(uid); if (iter == keepAliveRestartAfterUpgradeList_.end()) { return false; @@ -631,7 +645,7 @@ bool KeepAliveProcessManager::KeepAliveCheckNeedRestartAfterUpgrade(int32_t uid) bool KeepAliveProcessManager::KeepAliveIsRestartAfterUpdate(int32_t uid) { - std::lock_guard lock(restartAfterUpgradeMutex_); + std::lock_guard lock(restartAfterUpgradeMutex_); return keepAliveRestartAfterUpgradeList_.find(uid) != keepAliveRestartAfterUpgradeList_.end(); } diff --git a/test/fuzztest/keepaliveprocessmanagereighteenth_fuzzer/keepaliveprocessmanagereighteenth_fuzzer.cpp b/test/fuzztest/keepaliveprocessmanagereighteenth_fuzzer/keepaliveprocessmanagereighteenth_fuzzer.cpp index 18b0e3101c..ac96421afe 100644 --- a/test/fuzztest/keepaliveprocessmanagereighteenth_fuzzer/keepaliveprocessmanagereighteenth_fuzzer.cpp +++ b/test/fuzztest/keepaliveprocessmanagereighteenth_fuzzer/keepaliveprocessmanagereighteenth_fuzzer.cpp @@ -40,7 +40,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) FuzzedDataProvider fdp(data, size); bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); uid = fdp.ConsumeIntegral(); - KeepAliveProcessManager::GetInstance().SaveAppSeriviceRestartAfterUpgrade(bundleName, uid); + KeepAliveProcessManager::GetInstance().SaveAppServiceRestartAfterUpgrade(bundleName, uid); return true; } } diff --git a/test/unittest/ability_auto_startup_service_second_test/ability_auto_startup_service_second_test.cpp b/test/unittest/ability_auto_startup_service_second_test/ability_auto_startup_service_second_test.cpp index 68d4b9edff..43af9ad965 100644 --- a/test/unittest/ability_auto_startup_service_second_test/ability_auto_startup_service_second_test.cpp +++ b/test/unittest/ability_auto_startup_service_second_test/ability_auto_startup_service_second_test.cpp @@ -117,8 +117,8 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, RegisterAutoStartupSystemCallback_ MyFlag::flag_ = 1; system::SetBoolParameter("", true); - MockEdmAbilityAutoStartupListener stub; - sptr callback = stub.AsObject(); + sptr stub = new MockEdmAbilityAutoStartupListener(); + sptr callback = stub->AsObject(); int32_t result = abilityAutoStartupService->RegisterAutoStartupSystemCallback(nullptr); EXPECT_EQ(result, 0); EXPECT_EQ(abilityAutoStartupService->callbackVector_.size(), 1); @@ -172,6 +172,9 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, CheckAutoStartupData_002, TestSize result = abilityAutoStartupService->CheckAutoStartupData(bundleName, BASE_USER_RANGE); EXPECT_EQ(result, 0); + // Clear kvStorePtr_ to avoid calling CloseKvStore in destructor + DelayedSingleton::GetInstance()->kvStorePtr_ = nullptr; + GTEST_LOG_(INFO) << "CheckAutoStartupData_002 end"; } @@ -275,6 +278,9 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, InnerApplicationAutoStartupByEDM_0 result = abilityAutoStartupService->InnerApplicationAutoStartupByEDM(autoStartupInfo, false, false); EXPECT_EQ(result, 0); + // Clear kvStorePtr_ to avoid calling CloseKvStore in destructor + DelayedSingleton::GetInstance()->kvStorePtr_ = nullptr; + GTEST_LOG_(INFO) << "InnerApplicationAutoStartupByEDM_004 end"; } @@ -593,6 +599,9 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, CancelApplicationAutoStartup_003, GTEST_LOG_(INFO) << "CancelApplicationAutoStartup_003 start"; auto abilityAutoStartupService = std::make_shared(); EXPECT_NE(abilityAutoStartupService, nullptr); + auto kvStorePtr = std::make_shared(); + EXPECT_NE(kvStorePtr, nullptr); + DelayedSingleton::GetInstance()->kvStorePtr_ = kvStorePtr; MyFlag::flag_ = 1; system::SetBoolParameter("", true); AutoStartupInfo info; @@ -605,6 +614,8 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, CancelApplicationAutoStartup_003, info.setterType = AutoStartupSetterType::USER; int32_t result = abilityAutoStartupService->CancelApplicationAutoStartup(info); ASSERT_EQ(result, ERR_NAME_NOT_FOUND); + // Clear kvStorePtr_ to avoid calling CloseKvStore in destructor + DelayedSingleton::GetInstance()->kvStorePtr_ = nullptr; MyFlag::flag_ = 0; system::SetBoolParameter("", false); GTEST_LOG_(INFO) << "CancelApplicationAutoStartup_003 end"; @@ -745,8 +756,8 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, ExecuteCallbacks_001, TestSize.Lev EXPECT_NE(abilityAutoStartupService, nullptr); MyFlag::flag_ = 1; system::SetBoolParameter("", true); - MockEdmAbilityAutoStartupListener stub; - sptr callback = stub.AsObject(); + sptr stub = new MockEdmAbilityAutoStartupListener(); + sptr callback = stub->AsObject(); AutoStartupInfo info; info.userId = 0; info.setterUserId = 1; @@ -776,8 +787,8 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, ExecuteCallbacks_002, TestSize.Lev EXPECT_NE(abilityAutoStartupService, nullptr); MyFlag::flag_ = 1; system::SetBoolParameter("", true); - MockEdmAbilityAutoStartupListener stub; - sptr callback = stub.AsObject(); + sptr stub = new MockEdmAbilityAutoStartupListener(); + sptr callback = stub->AsObject(); AutoStartupInfo info; info.userId = 0; info.setterUserId = 1; @@ -807,8 +818,8 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, ExecuteCallbacks_003, TestSize.Lev EXPECT_NE(abilityAutoStartupService, nullptr); MyFlag::flag_ = 1; system::SetBoolParameter("", true); - MockEdmAbilityAutoStartupListener stub; - sptr callback = stub.AsObject(); + sptr stub = new MockEdmAbilityAutoStartupListener(); + sptr callback = stub->AsObject(); AutoStartupInfo info; info.userId = 1; info.setterUserId = 101; @@ -1050,6 +1061,9 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, CancelApplicationAutoStartupByEDM_ GTEST_LOG_(INFO) << "CancelApplicationAutoStartupByEDM_001 start"; auto abilityAutoStartupService = std::make_shared(); EXPECT_NE(abilityAutoStartupService, nullptr); + auto kvStorePtr = std::make_shared(); + EXPECT_NE(kvStorePtr, nullptr); + DelayedSingleton::GetInstance()->kvStorePtr_ = kvStorePtr; MyFlag::flag_ = 1; AutoStartupInfo info; info.bundleName = "hapAbilityInfoVisible"; @@ -1061,6 +1075,8 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, CancelApplicationAutoStartupByEDM_ info.setterType = AutoStartupSetterType::SYSTEM; int32_t result = abilityAutoStartupService->CancelApplicationAutoStartupByEDM(info, false); ASSERT_EQ(result, ERR_OK); + // Clear kvStorePtr_ to avoid calling CloseKvStore in destructor + DelayedSingleton::GetInstance()->kvStorePtr_ = nullptr; MyFlag::flag_ = 0; GTEST_LOG_(INFO) << "CancelApplicationAutoStartupByEDM_001 end"; } @@ -1230,6 +1246,9 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, QueryAllAutoStartupApplications_00 system::SetBoolParameter("", true); auto abilityAutoStartupService = std::make_shared(); EXPECT_NE(abilityAutoStartupService, nullptr); + auto kvStorePtr = std::make_shared(); + EXPECT_NE(kvStorePtr, nullptr); + DelayedSingleton::GetInstance()->kvStorePtr_ = kvStorePtr; AutoStartupInfo info; info.bundleName = "hapAbilityInfoVisible"; info.moduleName = "moduleNameTest"; @@ -1244,6 +1263,8 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, QueryAllAutoStartupApplications_00 int32_t userId = 100; result = abilityAutoStartupService->QueryAllAutoStartupApplications(infoList, userId); EXPECT_EQ(result, ERR_OK); + // Clear kvStorePtr_ to avoid calling CloseKvStore in destructor + DelayedSingleton::GetInstance()->kvStorePtr_ = nullptr; MyFlag::flag_ = 0; system::SetBoolParameter("", false); GTEST_LOG_(INFO) << "AbilityAutoStartupServiceSecondTest QueryAllAutoStartupApplications_003 end"; diff --git a/test/unittest/keep_alive_process_manager_test/keep_alive_process_manager_test.cpp b/test/unittest/keep_alive_process_manager_test/keep_alive_process_manager_test.cpp index 99ee979e84..1b6ac50984 100755 --- a/test/unittest/keep_alive_process_manager_test/keep_alive_process_manager_test.cpp +++ b/test/unittest/keep_alive_process_manager_test/keep_alive_process_manager_test.cpp @@ -2096,79 +2096,79 @@ HWTEST_F(KeepAliveProcessManagerTest, CheckPermission_002, TestSize.Level1) /* * Feature: KeepAliveProcessManager - * Function: SaveAppSeriviceRestartAfterUpgrade + * Function: SaveAppServiceRestartAfterUpgrade * SubFunction: NA - * FunctionPoints:SaveAppSeriviceRestartAfterUpgrade + * FunctionPoints:SaveAppServiceRestartAfterUpgrade * EnvConditions: NA - * CaseDescription: Verify SaveAppSeriviceRestartAfterUpgrade + * CaseDescription: Verify SaveAppServiceRestartAfterUpgrade */ -HWTEST_F(KeepAliveProcessManagerTest, SaveAppSeriviceRestartAfterUpgrade_001, TestSize.Level1) +HWTEST_F(KeepAliveProcessManagerTest, SaveAppServiceRestartAfterUpgrade_001, TestSize.Level1) { - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_001 start"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_001 start"; int32_t uid = 1; std::string bundleName = "testBundleName"; system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, true); AbilityKeepAliveService::callIsKeepAliveResult = false; auto keepAliveProcessManager = std::make_shared(); - keepAliveProcessManager->SaveAppSeriviceRestartAfterUpgrade(bundleName, uid); + keepAliveProcessManager->SaveAppServiceRestartAfterUpgrade(bundleName, uid); EXPECT_TRUE(AppMgrClient::isKeepAliveAppservice); - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_001 end"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_001 end"; } /* * Feature: KeepAliveProcessManager - * Function: SaveAppSeriviceRestartAfterUpgrade + * Function: SaveAppServiceRestartAfterUpgrade * SubFunction: NA - * FunctionPoints:SaveAppSeriviceRestartAfterUpgrade + * FunctionPoints:SaveAppServiceRestartAfterUpgrade * EnvConditions: NA - * CaseDescription: Verify SaveAppSeriviceRestartAfterUpgrade + * CaseDescription: Verify SaveAppServiceRestartAfterUpgrade */ -HWTEST_F(KeepAliveProcessManagerTest, SaveAppSeriviceRestartAfterUpgrade_002, TestSize.Level1) +HWTEST_F(KeepAliveProcessManagerTest, SaveAppServiceRestartAfterUpgrade_002, TestSize.Level1) { - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_002 start"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_002 start"; int32_t uid = 1; std::string bundleName = "testBundleName"; system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, true); AbilityKeepAliveService::callIsKeepAliveResult = true; auto keepAliveProcessManager = std::make_shared(); - keepAliveProcessManager->SaveAppSeriviceRestartAfterUpgrade(bundleName, uid); + keepAliveProcessManager->SaveAppServiceRestartAfterUpgrade(bundleName, uid); EXPECT_TRUE(AppMgrClient::isKeepAliveAppservice); - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_002 end"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_002 end"; } /* * Feature: KeepAliveProcessManager - * Function: SaveAppSeriviceRestartAfterUpgrade + * Function: SaveAppServiceRestartAfterUpgrade * SubFunction: NA - * FunctionPoints:SaveAppSeriviceRestartAfterUpgrade + * FunctionPoints:SaveAppServiceRestartAfterUpgrade * EnvConditions: NA - * CaseDescription: Verify SaveAppSeriviceRestartAfterUpgrade + * CaseDescription: Verify SaveAppServiceRestartAfterUpgrade */ -HWTEST_F(KeepAliveProcessManagerTest, SaveAppSeriviceRestartAfterUpgrade_003, TestSize.Level1) +HWTEST_F(KeepAliveProcessManagerTest, SaveAppServiceRestartAfterUpgrade_003, TestSize.Level1) { - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_003 start"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_003 start"; int32_t uid = 1; std::string bundleName = "testBundleName"; system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, true); AbilityKeepAliveService::callIsKeepAliveResult = true; AppMgrClient::ret = 0; auto keepAliveProcessManager = std::make_shared(); - keepAliveProcessManager->SaveAppSeriviceRestartAfterUpgrade(bundleName, uid); + keepAliveProcessManager->SaveAppServiceRestartAfterUpgrade(bundleName, uid); EXPECT_TRUE(AppMgrClient::isKeepAliveAppservice); - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_003 end"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_003 end"; } /* * Feature: KeepAliveProcessManager - * Function: SaveAppSeriviceRestartAfterUpgrade + * Function: SaveAppServiceRestartAfterUpgrade * SubFunction: NA - * FunctionPoints:SaveAppSeriviceRestartAfterUpgrade + * FunctionPoints:SaveAppServiceRestartAfterUpgrade * EnvConditions: NA - * CaseDescription: Verify SaveAppSeriviceRestartAfterUpgrade + * CaseDescription: Verify SaveAppServiceRestartAfterUpgrade */ -HWTEST_F(KeepAliveProcessManagerTest, SaveAppSeriviceRestartAfterUpgrade_004, TestSize.Level1) +HWTEST_F(KeepAliveProcessManagerTest, SaveAppServiceRestartAfterUpgrade_004, TestSize.Level1) { - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_004 start"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_004 start"; int32_t uid = 1; std::string bundleName = "testBundleName"; system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, true); @@ -2179,22 +2179,22 @@ HWTEST_F(KeepAliveProcessManagerTest, SaveAppSeriviceRestartAfterUpgrade_004, Te info.isKeepAliveAppService = false; AppMgrClient::infos = { info }; auto keepAliveProcessManager = std::make_shared(); - keepAliveProcessManager->SaveAppSeriviceRestartAfterUpgrade(bundleName, uid); + keepAliveProcessManager->SaveAppServiceRestartAfterUpgrade(bundleName, uid); EXPECT_TRUE(AppMgrClient::isKeepAliveAppservice); - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_004 end"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_004 end"; } /* * Feature: KeepAliveProcessManager - * Function: SaveAppSeriviceRestartAfterUpgrade + * Function: SaveAppServiceRestartAfterUpgrade * SubFunction: NA - * FunctionPoints:SaveAppSeriviceRestartAfterUpgrade + * FunctionPoints:SaveAppServiceRestartAfterUpgrade * EnvConditions: NA - * CaseDescription: Verify SaveAppSeriviceRestartAfterUpgrade + * CaseDescription: Verify SaveAppServiceRestartAfterUpgrade */ -HWTEST_F(KeepAliveProcessManagerTest, SaveAppSeriviceRestartAfterUpgrade_005, TestSize.Level1) +HWTEST_F(KeepAliveProcessManagerTest, SaveAppServiceRestartAfterUpgrade_005, TestSize.Level1) { - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_005 start"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_005 start"; int32_t uid = 1; std::string bundleName = "testBundleName"; system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, true); @@ -2205,22 +2205,22 @@ HWTEST_F(KeepAliveProcessManagerTest, SaveAppSeriviceRestartAfterUpgrade_005, Te info.isKeepAliveAppService = false; AppMgrClient::infos = { info }; auto keepAliveProcessManager = std::make_shared(); - keepAliveProcessManager->SaveAppSeriviceRestartAfterUpgrade(bundleName, uid); + keepAliveProcessManager->SaveAppServiceRestartAfterUpgrade(bundleName, uid); EXPECT_TRUE(AppMgrClient::isKeepAliveAppservice); - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_005 end"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_005 end"; } /* * Feature: KeepAliveProcessManager - * Function: SaveAppSeriviceRestartAfterUpgrade + * Function: SaveAppServiceRestartAfterUpgrade * SubFunction: NA - * FunctionPoints:SaveAppSeriviceRestartAfterUpgrade + * FunctionPoints:SaveAppServiceRestartAfterUpgrade * EnvConditions: NA - * CaseDescription: Verify SaveAppSeriviceRestartAfterUpgrade + * CaseDescription: Verify SaveAppServiceRestartAfterUpgrade */ -HWTEST_F(KeepAliveProcessManagerTest, SaveAppSeriviceRestartAfterUpgrade_006, TestSize.Level1) +HWTEST_F(KeepAliveProcessManagerTest, SaveAppServiceRestartAfterUpgrade_006, TestSize.Level1) { - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_006 start"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_006 start"; int32_t uid = 1; std::string bundleName = "testBundleName"; system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, true); @@ -2231,22 +2231,22 @@ HWTEST_F(KeepAliveProcessManagerTest, SaveAppSeriviceRestartAfterUpgrade_006, Te info.isKeepAliveAppService = true; AppMgrClient::infos = { info }; auto keepAliveProcessManager = std::make_shared(); - keepAliveProcessManager->SaveAppSeriviceRestartAfterUpgrade(bundleName, uid); + keepAliveProcessManager->SaveAppServiceRestartAfterUpgrade(bundleName, uid); EXPECT_TRUE(AppMgrClient::isKeepAliveAppservice); - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_006 end"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_006 end"; } /* * Feature: KeepAliveProcessManager - * Function: SaveAppSeriviceRestartAfterUpgrade + * Function: SaveAppServiceRestartAfterUpgrade * SubFunction: NA - * FunctionPoints:SaveAppSeriviceRestartAfterUpgrade + * FunctionPoints:SaveAppServiceRestartAfterUpgrade * EnvConditions: NA - * CaseDescription: Verify SaveAppSeriviceRestartAfterUpgrade + * CaseDescription: Verify SaveAppServiceRestartAfterUpgrade */ -HWTEST_F(KeepAliveProcessManagerTest, SaveAppSeriviceRestartAfterUpgrade_007, TestSize.Level1) +HWTEST_F(KeepAliveProcessManagerTest, SaveAppServiceRestartAfterUpgrade_007, TestSize.Level1) { - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_007 start"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_007 start"; int32_t uid = 1; std::string bundleName = "testBundleName"; system::SetBoolParameter(PRODUCT_ENTERPRISE_FEATURE_SETTING_ENABLED, true); @@ -2257,9 +2257,9 @@ HWTEST_F(KeepAliveProcessManagerTest, SaveAppSeriviceRestartAfterUpgrade_007, Te info.isKeepAliveAppService = true; AppMgrClient::infos = { info }; auto keepAliveProcessManager = std::make_shared(); - keepAliveProcessManager->SaveAppSeriviceRestartAfterUpgrade(bundleName, uid); + keepAliveProcessManager->SaveAppServiceRestartAfterUpgrade(bundleName, uid); EXPECT_FALSE(AppMgrClient::isKeepAliveAppservice); - GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_007 end"; + GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_007 end"; } /*