mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 12:43:16 -04:00
扫描问题修改
Signed-off-by: zhu-feimo <zhufeimo1@huawei.com> AI[53%] Human Fixed[0%] Human[47%] AI Adopted[100%]
This commit is contained in:
@@ -191,7 +191,11 @@ ErrCode CliToolMGRClient::BatchRegisterFunctions(const std::vector<FunctionInfo>
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#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<ToolInfo> &tools, ToolsRawD
|
||||
|
||||
int32_t ToolsRawData::ToToolInfoVec(const ToolsRawData &rawData, std::vector<ToolInfo> &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<const char *>(rawData.data), rawData.size);
|
||||
ss.seekg(0, std::ios::beg);
|
||||
uint32_t ssLength = static_cast<uint32_t>(ss.str().length());
|
||||
|
||||
uint32_t count = 0;
|
||||
ss.read(reinterpret_cast<char *>(&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<Too
|
||||
}
|
||||
tools.resize(count);
|
||||
for (uint32_t i = 0; i < count; ++i) {
|
||||
uint32_t toolSize = 0;
|
||||
ss.read(reinterpret_cast<char *>(&toolSize), sizeof(toolSize));
|
||||
if (toolSize > ssLength - static_cast<uint32_t>(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<ToolInfo>(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;
|
||||
|
||||
@@ -41,6 +41,7 @@ ohos_source_set("function_info") {
|
||||
|
||||
sources = [
|
||||
"src/function_info.cpp",
|
||||
"src/raw_data_utils.cpp",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
|
||||
@@ -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<FunctionInfo> &functions, FunctionsRawData &rawData);
|
||||
static int32_t FromFunctionInfoVec(const std::vector<FunctionInfo> &functions, FunctionsRawData &rawData);
|
||||
|
||||
/**
|
||||
* @brief Convert FunctionsRawData to vector of FunctionInfo
|
||||
|
||||
@@ -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 <cstdint>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<char *>(buf), len);
|
||||
return static_cast<bool>(ss);
|
||||
}
|
||||
|
||||
int32_t ReadItemToJson(std::stringstream &ss, uint32_t ssLength, bool allowComments,
|
||||
int32_t parseFailCode, nlohmann::json &out);
|
||||
|
||||
template <typename T>
|
||||
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
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "function_info.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <securec.h>
|
||||
@@ -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<std::string>();
|
||||
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<uint32_t>(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<std::string>();
|
||||
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<uint32_t>(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<int32_t>();
|
||||
if (typeValue >= 0 && typeValue < static_cast<int32_t>(FunctionType::END)) {
|
||||
output = static_cast<FunctionType>(typeValue);
|
||||
if (functionType.is_number_unsigned()) {
|
||||
auto val = functionType.get<nlohmann::json::number_unsigned_t>();
|
||||
if (val >= static_cast<decltype(val)>(FunctionType::END)) {
|
||||
TAG_LOGE(AAFwkTag::CLI_TOOL, "Invalid functionType value: %{public}llu, out of range [0, %{public}d)",
|
||||
static_cast<unsigned long long>(val), static_cast<int32_t>(FunctionType::END));
|
||||
return false;
|
||||
}
|
||||
output = static_cast<FunctionType>(val);
|
||||
return true;
|
||||
}
|
||||
TAG_LOGE(AAFwkTag::CLI_TOOL, "Invalid functionType value: %{public}d, out of range [0, %{public}d)",
|
||||
typeValue, static_cast<int32_t>(FunctionType::END));
|
||||
return false;
|
||||
auto val = functionType.get<nlohmann::json::number_integer_t>();
|
||||
if (val < 0 || val >= static_cast<decltype(val)>(FunctionType::END)) {
|
||||
TAG_LOGE(AAFwkTag::CLI_TOOL, "Invalid functionType value: %{public}lld, out of range [0, %{public}d)",
|
||||
static_cast<long long>(val), static_cast<int32_t>(FunctionType::END));
|
||||
return false;
|
||||
}
|
||||
output = static_cast<FunctionType>(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<uint32_t>(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<uint32_t>(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<FunctionInfo> &functions, FunctionsRawData &rawData)
|
||||
int32_t FunctionsRawData::FromFunctionInfoVec(const std::vector<FunctionInfo> &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<const char*>(&count), sizeof(count));
|
||||
@@ -307,16 +351,25 @@ void FunctionsRawData::FromFunctionInfoVec(const std::vector<FunctionInfo> &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<FunctionInfo> &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<const char *>(rawData.data), rawData.size);
|
||||
ss.seekg(0, std::ios::beg);
|
||||
uint32_t ssLength = static_cast<uint32_t>(ss.str().length());
|
||||
|
||||
uint32_t count = 0;
|
||||
ss.read(reinterpret_cast<char *>(&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<char *>(&functionSize), sizeof(functionSize));
|
||||
if (functionSize > ssLength - static_cast<uint32_t>(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<FunctionInfo>(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;
|
||||
|
||||
@@ -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 <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<std::streamoff>(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
|
||||
@@ -101,6 +101,7 @@ int32_t CliFunctionDataManager::EnsureFunctionsInitialized()
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
TAG_LOGE(AAFwkTag::CLI_TOOL, "KVStore not ready for functions initialization");
|
||||
return ERR_NO_INIT;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<number_integer_t>() 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<number_integer_t>() 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<int32_t>() 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<int32_t>() 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 ====================
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,6 +30,7 @@ enum class AutoStartupSetterType : int32_t {
|
||||
UNSPECIFIED = -1,
|
||||
SYSTEM = 0,
|
||||
USER = 1,
|
||||
MAX
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<int>(OHOS::AAFwk::Reason::REASON_MIN) ||
|
||||
exitReason > static_cast<int>(OHOS::AAFwk::Reason::REASON_MAX)) {
|
||||
return -1;
|
||||
}
|
||||
OHOS::AAFwk::Reason reason = static_cast<OHOS::AAFwk::Reason>(exitReason);
|
||||
std::string exitMsgStr = (exitMsg != nullptr) ? std::string(exitMsg) : std::string();
|
||||
OHOS::AAFwk::ExitReasonCompability exitReasonData = { reason, exitMsgStr };
|
||||
|
||||
@@ -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<KeepAliveRetryContext> context);
|
||||
|
||||
ffrt::mutex checkStatusBarTasksMutex_;
|
||||
std::vector<std::shared_ptr<CheckStatusBarTask>> checkStatusBarTasks_;
|
||||
std::mutex restartAfterUpgradeMutex_;
|
||||
ffrt::mutex restartAfterUpgradeMutex_;
|
||||
std::set<int32_t> restartAfterUpgradeList_;
|
||||
std::set<int32_t> keepAliveRestartAfterUpgradeList_;
|
||||
|
||||
|
||||
@@ -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<int32_t>(info.setterType));
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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<int32_t>(info.setterType));
|
||||
DistributedKv::Key key = ConvertAutoStartupDataToKey(info);
|
||||
DistributedKv::Value value = ConvertAutoStartupStatusToValue(info, isAutoStartup, isEdmForce);
|
||||
DistributedKv::Status status;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null kvStore");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
}
|
||||
|
||||
DistributedKv::Status status;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null kvStore");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
@@ -326,22 +293,13 @@ AutoStartupStatus AbilityAutoStartupDataManager::QueryAutoStartupData(const Auto
|
||||
startupStatus.code = ERR_NO_INIT;
|
||||
return startupStatus;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null kvStore");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
|
||||
status = kvStorePtr_->GetEntries(nullptr, allEntries);
|
||||
}
|
||||
if (status != DistributedKv::Status::SUCCESS) {
|
||||
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "GetEntries: %{public}d", status);
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<AutoStartupInfo> &infoList, const std::string &accessTokenId)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::AUTO_STARTUP, "called");
|
||||
|
||||
std::vector<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "null kvStore");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<int32_t>();
|
||||
}
|
||||
if (jsonObject.contains(JSON_KEY_SETTER_TYPE) && jsonObject[JSON_KEY_SETTER_TYPE].is_number()) {
|
||||
startupStatus.setterType =
|
||||
static_cast<AutoStartupSetterType>(jsonObject.at(JSON_KEY_SETTER_TYPE).get<int32_t>());
|
||||
int32_t setterTypeValue = jsonObject.at(JSON_KEY_SETTER_TYPE).get<int32_t>();
|
||||
if (setterTypeValue < static_cast<int32_t>(AutoStartupSetterType::UNSPECIFIED) ||
|
||||
setterTypeValue >= static_cast<int32_t>(AutoStartupSetterType::MAX)) {
|
||||
TAG_LOGE(AAFwkTag::AUTO_STARTUP, "Invalid setterType: %{public}d, using UNSPECIFIED", setterTypeValue);
|
||||
startupStatus.setterType = AutoStartupSetterType::UNSPECIFIED;
|
||||
} else {
|
||||
startupStatus.setterType = static_cast<AutoStartupSetterType>(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<bool>();
|
||||
|
||||
@@ -43,7 +43,26 @@ constexpr const char* HIDDEN_START_AUTOSTARTUP = "hiddenStartAutoStartup";
|
||||
|
||||
AbilityAutoStartupService::AbilityAutoStartupService() {}
|
||||
|
||||
AbilityAutoStartupService::~AbilityAutoStartupService() {}
|
||||
AbilityAutoStartupService::~AbilityAutoStartupService()
|
||||
{
|
||||
{
|
||||
std::lock_guard<std::mutex> deathLock(deathRecipientsMutex_);
|
||||
for (auto &entry : deathRecipients_) {
|
||||
if (entry.first != nullptr && entry.second != nullptr) {
|
||||
wptr<IRemoteObject> weakCallback = entry.first;
|
||||
auto callback = weakCallback.promote();
|
||||
if (callback != nullptr) {
|
||||
callback->RemoveDeathRecipient(entry.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
deathRecipients_.clear();
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(autoStartUpMutex_);
|
||||
callbackVector_.clear();
|
||||
}
|
||||
}
|
||||
|
||||
int32_t AbilityAutoStartupService::RegisterAutoStartupSystemCallback(const sptr<IRemoteObject> &callback)
|
||||
{
|
||||
@@ -81,9 +100,9 @@ int32_t AbilityAutoStartupService::UnregisterAutoStartupSystemCallback(const spt
|
||||
return code;
|
||||
}
|
||||
|
||||
bool isFound = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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> wantSenderInfo(data.ReadParcelable<WantSenderInfo>());
|
||||
@@ -4004,7 +4004,7 @@ int32_t AbilityManagerStub::KillProcessWithReasonInner(MessageParcel &data, Mess
|
||||
int32_t pid = data.ReadInt32();
|
||||
std::unique_ptr<ExitReason> reason(data.ReadParcelable<ExitReason>());
|
||||
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);
|
||||
|
||||
@@ -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<AppScheduler>::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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 <typename EnumType>
|
||||
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<int32_t>();
|
||||
if (value < static_cast<int32_t>(EnumType::UNSPECIFIED) ||
|
||||
value >= static_cast<int32_t>(EnumType::MAX)) {
|
||||
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "Invalid %{public}s: %{public}d", fieldName.c_str(), value);
|
||||
return defaultValue;
|
||||
}
|
||||
return static_cast<EnumType>(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<std::mutex> 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<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null kvStore");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
}
|
||||
info.bundleName.c_str(), info.userId, static_cast<int32_t>(info.appType),
|
||||
static_cast<int32_t>(info.setter));
|
||||
|
||||
DistributedKv::Key key = ConvertKeepAliveDataToKey(info);
|
||||
DistributedKv::Value value = ConvertKeepAliveStatusToValue(info);
|
||||
DistributedKv::Status status;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<int32_t>(info.appType),
|
||||
static_cast<int32_t>(info.setter));
|
||||
|
||||
std::vector<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null kvStore");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
@@ -227,22 +243,13 @@ KeepAliveStatus AbilityKeepAliveDataManager::QueryKeepAliveData(const KeepAliveI
|
||||
kaStatus.code = ERR_NO_INIT;
|
||||
return kaStatus;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<int32_t>(queryParam.appType),
|
||||
static_cast<int32_t>(queryParam.setter));
|
||||
|
||||
std::vector<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null kvStore");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
|
||||
status = kvStorePtr_->GetEntries(nullptr, allEntries);
|
||||
}
|
||||
if (status != DistributedKv::Status::SUCCESS) {
|
||||
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "GetEntries: %{public}d", status);
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(kvStorePtrMutex_);
|
||||
if (!CheckKvStore()) {
|
||||
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "null kvStore");
|
||||
return ERR_NO_INIT;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<DistributedKv::Entry> allEntries;
|
||||
DistributedKv::Status status = DistributedKv::Status::SUCCESS;
|
||||
{
|
||||
std::lock_guard<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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<int32_t>());
|
||||
}
|
||||
|
||||
status.setter = ParseEnum<KeepAliveSetter>(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<int32_t>();
|
||||
}
|
||||
if (jsonObject.contains(JSON_KEY_POLICY) && jsonObject[JSON_KEY_POLICY].is_number()) {
|
||||
status.policy = KeepAlivePolicy(jsonObject.at(JSON_KEY_POLICY).get<int32_t>());
|
||||
}
|
||||
|
||||
status.policy = ParseEnum<KeepAlivePolicy>(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<int32_t>();
|
||||
}
|
||||
|
||||
if (jsonObject.contains(JSON_KEY_APP_TYPE) && jsonObject[JSON_KEY_APP_TYPE].is_number()) {
|
||||
info.appType = KeepAliveAppType(jsonObject.at(JSON_KEY_APP_TYPE).get<int32_t>());
|
||||
}
|
||||
|
||||
if (jsonObject.contains(JSON_KEY_SETTER) && jsonObject[JSON_KEY_SETTER].is_number()) {
|
||||
info.setter = KeepAliveSetter(jsonObject.at(JSON_KEY_SETTER).get<int32_t>());
|
||||
}
|
||||
info.appType = ParseEnum<KeepAliveAppType>(jsonObject, JSON_KEY_APP_TYPE,
|
||||
KeepAliveAppType::UNSPECIFIED, "appType");
|
||||
info.setter = ParseEnum<KeepAliveSetter>(jsonObject, JSON_KEY_SETTER,
|
||||
KeepAliveSetter::UNSPECIFIED, "setter");
|
||||
info.policy = ParseEnum<KeepAlivePolicy>(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<int32_t>();
|
||||
}
|
||||
|
||||
if (jsonObject.contains(JSON_KEY_POLICY) && jsonObject[JSON_KEY_POLICY].is_number()) {
|
||||
info.policy = KeepAlivePolicy(jsonObject.at(JSON_KEY_POLICY).get<int32_t>());
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<int32_t>(status.setter) <= static_cast<int32_t>(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)
|
||||
|
||||
@@ -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 <typename EnumType>
|
||||
EnumType ValidateEnum(int32_t value, EnumType defaultValue, const char *fieldName)
|
||||
{
|
||||
if (value < static_cast<int32_t>(EnumType::UNSPECIFIED) ||
|
||||
value >= static_cast<int32_t>(EnumType::MAX)) {
|
||||
TAG_LOGE(AAFwkTag::KEEP_ALIVE, "Invalid %{public}s: %{public}d", fieldName, value);
|
||||
return defaultValue;
|
||||
}
|
||||
return static_cast<EnumType>(value);
|
||||
}
|
||||
} // namespace
|
||||
bool KeepAliveInfo::ReadFromParcel(Parcel &parcel)
|
||||
{
|
||||
bundleName = Str16ToStr8(parcel.ReadString16());
|
||||
userId = parcel.ReadInt32();
|
||||
appType = KeepAliveAppType(parcel.ReadInt32());
|
||||
setter = KeepAliveSetter(parcel.ReadInt32());
|
||||
|
||||
appType = ValidateEnum<KeepAliveAppType>(parcel.ReadInt32(),
|
||||
KeepAliveAppType::UNSPECIFIED, "appType");
|
||||
setter = ValidateEnum<KeepAliveSetter>(parcel.ReadInt32(),
|
||||
KeepAliveSetter::UNSPECIFIED, "setter");
|
||||
setterId = parcel.ReadInt32();
|
||||
policy = KeepAlivePolicy(parcel.ReadInt32());
|
||||
policy = ValidateEnum<KeepAlivePolicy>(parcel.ReadInt32(),
|
||||
KeepAlivePolicy::UNSPECIFIED, "policy");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<KeepAliveRetryContext>();
|
||||
context->info = info;
|
||||
context->accessTokenId = bundleInfo.applicationInfo.accessTokenId;
|
||||
context->isMultiInstance = isMultiInstance;
|
||||
context->triedCount = 0;
|
||||
ScheduleRetryTask(context);
|
||||
}
|
||||
|
||||
void KeepAliveProcessManager::ScheduleRetryTask(std::shared_ptr<KeepAliveRetryContext> 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<std::mutex> lock(restartAfterUpgradeMutex_);
|
||||
std::lock_guard<ffrt::mutex> 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<std::mutex> lock(restartAfterUpgradeMutex_);
|
||||
std::lock_guard<ffrt::mutex> 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<std::mutex> lock(restartAfterUpgradeMutex_);
|
||||
std::lock_guard<ffrt::mutex> 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<std::mutex> lock(restartAfterUpgradeMutex_);
|
||||
std::lock_guard<ffrt::mutex> 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<std::mutex> lock(restartAfterUpgradeMutex_);
|
||||
std::lock_guard<ffrt::mutex> lock(restartAfterUpgradeMutex_);
|
||||
return keepAliveRestartAfterUpgradeList_.find(uid) != keepAliveRestartAfterUpgradeList_.end();
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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<int32_t>();
|
||||
KeepAliveProcessManager::GetInstance().SaveAppSeriviceRestartAfterUpgrade(bundleName, uid);
|
||||
KeepAliveProcessManager::GetInstance().SaveAppServiceRestartAfterUpgrade(bundleName, uid);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+29
-8
@@ -117,8 +117,8 @@ HWTEST_F(AbilityAutoStartupServiceSecondTest, RegisterAutoStartupSystemCallback_
|
||||
|
||||
MyFlag::flag_ = 1;
|
||||
system::SetBoolParameter("", true);
|
||||
MockEdmAbilityAutoStartupListener stub;
|
||||
sptr<IRemoteObject> callback = stub.AsObject();
|
||||
sptr<MockEdmAbilityAutoStartupListener> stub = new MockEdmAbilityAutoStartupListener();
|
||||
sptr<IRemoteObject> 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<AbilityAutoStartupDataManager>::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<AbilityAutoStartupDataManager>::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<AbilityAutoStartupService>();
|
||||
EXPECT_NE(abilityAutoStartupService, nullptr);
|
||||
auto kvStorePtr = std::make_shared<MockSingleKvStore>();
|
||||
EXPECT_NE(kvStorePtr, nullptr);
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::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<AbilityAutoStartupDataManager>::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<IRemoteObject> callback = stub.AsObject();
|
||||
sptr<MockEdmAbilityAutoStartupListener> stub = new MockEdmAbilityAutoStartupListener();
|
||||
sptr<IRemoteObject> 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<IRemoteObject> callback = stub.AsObject();
|
||||
sptr<MockEdmAbilityAutoStartupListener> stub = new MockEdmAbilityAutoStartupListener();
|
||||
sptr<IRemoteObject> 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<IRemoteObject> callback = stub.AsObject();
|
||||
sptr<MockEdmAbilityAutoStartupListener> stub = new MockEdmAbilityAutoStartupListener();
|
||||
sptr<IRemoteObject> 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<AbilityAutoStartupService>();
|
||||
EXPECT_NE(abilityAutoStartupService, nullptr);
|
||||
auto kvStorePtr = std::make_shared<MockSingleKvStore>();
|
||||
EXPECT_NE(kvStorePtr, nullptr);
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::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<AbilityAutoStartupDataManager>::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<AbilityAutoStartupService>();
|
||||
EXPECT_NE(abilityAutoStartupService, nullptr);
|
||||
auto kvStorePtr = std::make_shared<MockSingleKvStore>();
|
||||
EXPECT_NE(kvStorePtr, nullptr);
|
||||
DelayedSingleton<AbilityAutoStartupDataManager>::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<AbilityAutoStartupDataManager>::GetInstance()->kvStorePtr_ = nullptr;
|
||||
MyFlag::flag_ = 0;
|
||||
system::SetBoolParameter("", false);
|
||||
GTEST_LOG_(INFO) << "AbilityAutoStartupServiceSecondTest QueryAllAutoStartupApplications_003 end";
|
||||
|
||||
@@ -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>();
|
||||
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>();
|
||||
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>();
|
||||
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>();
|
||||
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>();
|
||||
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>();
|
||||
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>();
|
||||
keepAliveProcessManager->SaveAppSeriviceRestartAfterUpgrade(bundleName, uid);
|
||||
keepAliveProcessManager->SaveAppServiceRestartAfterUpgrade(bundleName, uid);
|
||||
EXPECT_FALSE(AppMgrClient::isKeepAliveAppservice);
|
||||
GTEST_LOG_(INFO) << "SaveAppSeriviceRestartAfterUpgrade_007 end";
|
||||
GTEST_LOG_(INFO) << "SaveAppServiceRestartAfterUpgrade_007 end";
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user