mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
OTA升级后常驻变为非常驻时删除数据库记录
Signed-off-by: zhangyuhang72 <zhangyuhang72@huawei.com> Change-Id: I927399ecfc924959d9876b8494362b2a6df5f08e
This commit is contained in:
@@ -78,7 +78,7 @@ public:
|
||||
int32_t VerifyConfigurationPermissions(const std::string &bundleName, const std::string &callerName);
|
||||
int32_t GetResidentProcessEnable(const std::string &bundleName, bool &enable);
|
||||
int32_t UpdateResidentProcessEnable(const std::string &bundleName, bool enable);
|
||||
int32_t RemoveData(std::string &bundleName);
|
||||
int32_t RemoveData(const std::string &bundleName);
|
||||
int32_t GetResidentProcessRawData(const std::string &bundleName, const std::string &callerName);
|
||||
private:
|
||||
std::unique_ptr<RdbDataManager> rdbMgr_ = nullptr;
|
||||
|
||||
@@ -236,7 +236,7 @@ int32_t AmsResidentProcessRdb::UpdateResidentProcessEnable(const std::string &bu
|
||||
return rdbMgr_->UpdateData(valuesBucket, absRdbPredicates);
|
||||
}
|
||||
|
||||
int32_t AmsResidentProcessRdb::RemoveData(std::string &bundleName)
|
||||
int32_t AmsResidentProcessRdb::RemoveData(const std::string &bundleName)
|
||||
{
|
||||
if (bundleName.empty()) {
|
||||
TAG_LOGE(AAFwkTag::ABILITYMGR, "null bundleName");
|
||||
|
||||
@@ -93,6 +93,12 @@ void ResidentProcessManager::StartResidentProcessWithMainElementPerBundle(const
|
||||
bool keepAliveEnable = bundleInfo.isKeepAlive;
|
||||
// Check startup permissions
|
||||
AmsResidentProcessRdb::GetInstance().GetResidentProcessEnable(bundleInfo.name, keepAliveEnable);
|
||||
if (!bundleInfo.isKeepAlive && keepAliveEnable) {
|
||||
auto &bundleName = bundleInfo.name;
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR, "keepAliveBundle changed, bundle:%{public}s", bundleName.c_str());
|
||||
AmsResidentProcessRdb::GetInstance().RemoveData(bundleName);
|
||||
keepAliveEnable = false;
|
||||
}
|
||||
TAG_LOGI(AAFwkTag::ABILITYMGR,
|
||||
"Precheck,bundle:%{public}s, process:%{public}s, keepAlive:%{public}d, enable:%{public}d",
|
||||
bundleInfo.name.c_str(), processName.c_str(), bundleInfo.isKeepAlive, keepAliveEnable);
|
||||
|
||||
@@ -49,7 +49,9 @@ bool KeepAliveUtils::IsKeepAliveBundle(const AppExecFwk::BundleInfo &bundleInfo,
|
||||
}
|
||||
|
||||
bool keepAliveEnable = bundleInfo.isKeepAlive;
|
||||
AbilityRuntime::AmsResidentProcessRdb::GetInstance().GetResidentProcessEnable(bundleInfo.name, keepAliveEnable);
|
||||
if (keepAliveEnable) {
|
||||
AbilityRuntime::AmsResidentProcessRdb::GetInstance().GetResidentProcessEnable(bundleInfo.name, keepAliveEnable);
|
||||
}
|
||||
if (keepAliveEnable) {
|
||||
type = KeepAliveType::RESIDENT_PROCESS;
|
||||
}
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2025 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 MOCK_OHOS_ABILITY_RUNTIME_RDB_ABILITY_RESIDENT_PROCESS_RDB_H
|
||||
#define MOCK_OHOS_ABILITY_RUNTIME_RDB_ABILITY_RESIDENT_PROCESS_RDB_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
enum RdbResult : int32_t {
|
||||
Rdb_OK = 0,
|
||||
/* Representative database initialization failed */
|
||||
Rdb_Init_Err,
|
||||
/* Failed to parse initialization file */
|
||||
Rdb_Parse_File_Err,
|
||||
/* Parameter check failed */
|
||||
Rdb_Parameter_Err,
|
||||
/* Failed to query permission settings for resident processes */
|
||||
Rdb_Permissions_Err,
|
||||
/* Database query failed, key may not exist */
|
||||
Rdb_Search_Record_Err
|
||||
};
|
||||
|
||||
class AmsResidentProcessRdb final {
|
||||
public:
|
||||
AmsResidentProcessRdb() {}
|
||||
~AmsResidentProcessRdb() {}
|
||||
|
||||
static AmsResidentProcessRdb &GetInstance()
|
||||
{
|
||||
static AmsResidentProcessRdb instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
MOCK_METHOD0(Init, int32_t());
|
||||
MOCK_METHOD2(VerifyConfigurationPermissions, int32_t(const std::string &bundleName, const std::string &callerName));
|
||||
MOCK_METHOD2(GetResidentProcessEnable, int32_t(const std::string &bundleName, bool &enable));
|
||||
MOCK_METHOD2(UpdateResidentProcessEnable, int32_t(const std::string &bundleName, bool enable));
|
||||
MOCK_METHOD1(RemoveData, int32_t(const std::string &bundleName));
|
||||
MOCK_METHOD2(GetResidentProcessRawData, int32_t(const std::string &bundleName, const std::string &callerName));
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_RDB_ABILITY_RESIDENT_PROCESS_RDB_H
|
||||
@@ -185,6 +185,43 @@ HWTEST_F(ResidentProcessManagerTest, StartResidentProcessWithMainElementPerBundl
|
||||
EXPECT_EQ((int)needEraseIndexSet.size(), 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: ResidentProcessManager
|
||||
* Function: StartResidentProcessWithMainElementPerBundle
|
||||
* SubFunction: NA
|
||||
* FunctionPoints:ResidentProcessManager StartResidentProcessWithMainElementPerBundle
|
||||
* EnvConditions: NA
|
||||
* CaseDescription: Verify StartResidentProcessWithMainElementPerBundle
|
||||
*/
|
||||
HWTEST_F(ResidentProcessManagerTest, StartResidentProcessWithMainElementPerBundle_002, TestSize.Level1)
|
||||
{
|
||||
GTEST_LOG_(INFO) << "StartResidentProcessWithMainElementPerBundle_002 start";
|
||||
|
||||
std::shared_ptr<ResidentProcessManager> manager = std::make_shared<ResidentProcessManager>();
|
||||
AppExecFwk::BundleInfo bundleInfo;
|
||||
bundleInfo.isKeepAlive = false;
|
||||
bundleInfo.name = "com.example.test";
|
||||
size_t index = 1;
|
||||
std::set<uint32_t> needEraseIndexSet;
|
||||
int32_t userId = 0;
|
||||
|
||||
bool keepAliveEnable = true;
|
||||
EXPECT_CALL(AmsResidentProcessRdb::GetInstance(), GetResidentProcessEnable(_, _))
|
||||
.Times(1)
|
||||
.WillOnce(DoAll(SetArgReferee<1>(keepAliveEnable), Return(RdbResult::Rdb_OK)));
|
||||
|
||||
EXPECT_CALL(AmsResidentProcessRdb::GetInstance(), RemoveData(_))
|
||||
.Times(1)
|
||||
.WillOnce(Return(RdbResult::Rdb_OK));
|
||||
|
||||
manager->StartResidentProcessWithMainElementPerBundle(bundleInfo, index, needEraseIndexSet, userId);
|
||||
|
||||
|
||||
EXPECT_EQ(needEraseIndexSet.size(), 1);
|
||||
|
||||
GTEST_LOG_(INFO) << "StartResidentProcessWithMainElementPerBundle_002 end";
|
||||
}
|
||||
|
||||
/*
|
||||
* Feature: ResidentProcessManager
|
||||
* Function: PutResidentAbility
|
||||
|
||||
Reference in New Issue
Block a user