mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
@@ -439,10 +439,11 @@ public:
|
||||
* Register configuration observer.
|
||||
*
|
||||
* @param observer Configuration observer. When configuration changed, observer will be called.
|
||||
* @param userId The userId provided by caller.
|
||||
* @return Returns RESULT_OK on success, others on failure.
|
||||
*/
|
||||
virtual AppMgrResultCode RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer);
|
||||
|
||||
virtual AppMgrResultCode RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer,
|
||||
const int32_t userId = -1);
|
||||
/**
|
||||
* Unregister configuration observer.
|
||||
*
|
||||
|
||||
@@ -484,10 +484,11 @@ public:
|
||||
* Register configuration observer.
|
||||
*
|
||||
* @param observer Configuration observer. When configuration changed, observer will be called.
|
||||
* @param userId The userId provided by caller.
|
||||
* @return Returns RESULT_OK on success, others on failure.
|
||||
*/
|
||||
virtual int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) = 0;
|
||||
|
||||
virtual int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer,
|
||||
const int32_t userId = -1) = 0;
|
||||
/**
|
||||
* Unregister configuration observer.
|
||||
*
|
||||
|
||||
@@ -446,7 +446,8 @@ public:
|
||||
virtual int32_t UpdateConfigurationByBundleName(const Configuration &config, const std::string &name,
|
||||
int32_t appIndex = 0) override;
|
||||
|
||||
virtual int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override;
|
||||
virtual int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer,
|
||||
const int32_t userId = -1) override;
|
||||
|
||||
virtual int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override;
|
||||
|
||||
|
||||
@@ -895,11 +895,12 @@ AppMgrResultCode AppMgrClient::UpdateConfigurationByBundleName(const Configurati
|
||||
return AppMgrResultCode::RESULT_OK;
|
||||
}
|
||||
|
||||
AppMgrResultCode AppMgrClient::RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer)
|
||||
AppMgrResultCode AppMgrClient::RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer,
|
||||
const int32_t userId)
|
||||
{
|
||||
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
|
||||
if (service != nullptr) {
|
||||
int32_t result = service->RegisterConfigurationObserver(observer);
|
||||
int32_t result = service->RegisterConfigurationObserver(observer, userId);
|
||||
if (result == ERR_OK) {
|
||||
return AppMgrResultCode::RESULT_OK;
|
||||
}
|
||||
|
||||
@@ -1076,7 +1076,8 @@ int32_t AppMgrProxy::GetConfiguration(Configuration& config)
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int32_t AppMgrProxy::RegisterConfigurationObserver(const sptr<IConfigurationObserver>& observer)
|
||||
int32_t AppMgrProxy::RegisterConfigurationObserver(const sptr<IConfigurationObserver>& observer,
|
||||
const int32_t userId)
|
||||
{
|
||||
if (!observer) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "observer null");
|
||||
@@ -1095,6 +1096,11 @@ int32_t AppMgrProxy::RegisterConfigurationObserver(const sptr<IConfigurationObse
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
|
||||
if (!data.WriteInt32(userId)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "invalid userId");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
|
||||
auto error = SendRequest(AppMgrInterfaceCode::REGISTER_CONFIGURATION_OBSERVER, data, reply, option);
|
||||
if (error != NO_ERROR) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error);
|
||||
|
||||
@@ -1122,7 +1122,8 @@ int32_t AppMgrStub::HandleRegisterConfigurationObserver(MessageParcel &data, Mes
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Observer is null.");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
int32_t result = RegisterConfigurationObserver(observer);
|
||||
int32_t userId = data.ReadInt32();
|
||||
int32_t result = RegisterConfigurationObserver(observer, userId);
|
||||
reply.WriteInt32(result);
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -465,11 +465,11 @@ public:
|
||||
/**
|
||||
* @brief register a configuration observer which will receive notifies when updated.
|
||||
* @param observer the configuration observer to receive notify.
|
||||
*
|
||||
* @param userId The userId provided by caller.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer) override;
|
||||
|
||||
virtual int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer,
|
||||
const int32_t userId = -1) override;
|
||||
/**
|
||||
* @brief unregister a configuration observer registered before.
|
||||
* @param observer the configuration observer registered before.
|
||||
|
||||
@@ -822,7 +822,8 @@ public:
|
||||
|
||||
std::shared_ptr<AppExecFwk::Configuration> GetConfiguration();
|
||||
|
||||
int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver>& observer);
|
||||
int32_t RegisterConfigurationObserver(const sptr<IConfigurationObserver>& observer,
|
||||
const int32_t userId = -1);
|
||||
|
||||
int32_t UnregisterConfigurationObserver(const sptr<IConfigurationObserver>& observer);
|
||||
|
||||
|
||||
@@ -1151,13 +1151,14 @@ int32_t AppMgrService::UpdateConfigurationByBundleName(const Configuration& conf
|
||||
return appMgrServiceInner_->UpdateConfigurationByBundleName(config, name, appIndex);
|
||||
}
|
||||
|
||||
int32_t AppMgrService::RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer)
|
||||
int32_t AppMgrService::RegisterConfigurationObserver(const sptr<IConfigurationObserver> &observer,
|
||||
const int32_t userId)
|
||||
{
|
||||
if (!IsReady()) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "not ready");
|
||||
return ERR_INVALID_OPERATION;
|
||||
}
|
||||
return appMgrServiceInner_->RegisterConfigurationObserver(observer);
|
||||
return appMgrServiceInner_->RegisterConfigurationObserver(observer, userId);
|
||||
}
|
||||
|
||||
int32_t AppMgrService::UnregisterConfigurationObserver(const sptr<IConfigurationObserver> &observer)
|
||||
|
||||
@@ -6028,7 +6028,8 @@ void AppMgrServiceInner::HandleConfigurationChange(const Configuration& config,
|
||||
}
|
||||
}
|
||||
|
||||
int32_t AppMgrServiceInner::RegisterConfigurationObserver(const sptr<IConfigurationObserver>& observer)
|
||||
int32_t AppMgrServiceInner::RegisterConfigurationObserver(const sptr<IConfigurationObserver>& observer,
|
||||
const int32_t userId)
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "called");
|
||||
if (!AAFwk::PermissionVerification::GetInstance()->IsSACall()) {
|
||||
@@ -6049,8 +6050,12 @@ int32_t AppMgrServiceInner::RegisterConfigurationObserver(const sptr<IConfigurat
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "observer exist");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
configurationObservers_.push_back(
|
||||
ConfigurationObserverWithUserId { observer, GetUserIdByUid(IPCSkeleton::GetCallingUid()) });
|
||||
if (userId >= 0) {
|
||||
configurationObservers_.push_back(ConfigurationObserverWithUserId { observer, userId });
|
||||
} else {
|
||||
configurationObservers_.push_back(
|
||||
ConfigurationObserverWithUserId { observer, GetUserIdByUid(IPCSkeleton::GetCallingUid()) });
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,8 @@ public:
|
||||
MOCK_METHOD2(GetRenderProcessTerminationStatus, int(pid_t renderPid, int& status));
|
||||
MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config));
|
||||
MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId));
|
||||
MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD2(RegisterConfigurationObserver,
|
||||
int32_t(const sptr<IConfigurationObserver>& observer, const int32_t userId));
|
||||
MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName));
|
||||
MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName,
|
||||
|
||||
@@ -78,7 +78,8 @@ public:
|
||||
const AppExecFwk::ConfigurationPolicy &policy, const int32_t userId));
|
||||
MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name,
|
||||
int32_t appIndex));
|
||||
MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD2(RegisterConfigurationObserver,
|
||||
int32_t(const sptr<IConfigurationObserver>& observer, const int32_t userId));
|
||||
MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName));
|
||||
MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName,
|
||||
|
||||
@@ -120,7 +120,7 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_RegisterConfigurationObserver_0100, Test
|
||||
EXPECT_EQ(result, AppMgrResultCode::RESULT_OK);
|
||||
|
||||
sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
|
||||
result = appMgrClient->RegisterConfigurationObserver(observer);
|
||||
result = appMgrClient->RegisterConfigurationObserver(observer, -1);
|
||||
EXPECT_EQ(result, AppMgrResultCode::RESULT_OK);
|
||||
|
||||
sleep(1);
|
||||
@@ -152,11 +152,11 @@ HWTEST_F(AppMgrClientTest, AppMgrClient_RegisterConfigurationObserver_0200, Test
|
||||
EXPECT_EQ(result, AppMgrResultCode::RESULT_OK);
|
||||
|
||||
sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
|
||||
result = appMgrClient->RegisterConfigurationObserver(observer);
|
||||
result = appMgrClient->RegisterConfigurationObserver(observer, -1);
|
||||
EXPECT_EQ(result, AppMgrResultCode::RESULT_OK);
|
||||
|
||||
sptr<MockConfigurationObserver> observerOther(new (std::nothrow) MockConfigurationObserver());
|
||||
result = appMgrClient->RegisterConfigurationObserver(observerOther);
|
||||
result = appMgrClient->RegisterConfigurationObserver(observerOther, -1);
|
||||
EXPECT_EQ(result, AppMgrResultCode::RESULT_OK);
|
||||
|
||||
sleep(1);
|
||||
|
||||
+2
-1
@@ -75,7 +75,8 @@ public:
|
||||
MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId));
|
||||
MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name,
|
||||
int32_t appIndex));
|
||||
MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD2(RegisterConfigurationObserver,
|
||||
int32_t(const sptr<IConfigurationObserver>& observer, const int32_t userId));
|
||||
MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName));
|
||||
MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName,
|
||||
|
||||
@@ -1242,7 +1242,7 @@ HWTEST_F(AppMgrClientTest, RegisterConfigurationObserver_001, TestSize.Level1)
|
||||
{
|
||||
auto appMgrClient = std::make_unique<AppMgrClient>();
|
||||
sptr<IConfigurationObserver> observer;
|
||||
appMgrClient->RegisterConfigurationObserver(observer);
|
||||
appMgrClient->RegisterConfigurationObserver(observer, -1);
|
||||
EXPECT_NE(appMgrClient, nullptr);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1946,7 +1946,7 @@ HWTEST_F(AppMgrServiceInnerSeventhTest, RegisterConfigurationObserver_001, TestS
|
||||
auto appMgrServiceInner = std::make_shared<AppMgrServiceInner>();
|
||||
AAFwk::MyStatus::GetInstance().isSACall_ = false;
|
||||
|
||||
auto ret = appMgrServiceInner->RegisterConfigurationObserver(nullptr);
|
||||
auto ret = appMgrServiceInner->RegisterConfigurationObserver(nullptr, -1);
|
||||
EXPECT_EQ(ret, ERR_INVALID_VALUE);
|
||||
TAG_LOGI(AAFwkTag::TEST, "RegisterConfigurationObserver_001 end");
|
||||
}
|
||||
|
||||
@@ -2871,11 +2871,11 @@ HWTEST_F(AppMgrServiceInnerTest, RegisterConfigurationObserver_001, TestSize.Lev
|
||||
|
||||
appMgrServiceInner->configurationObservers_.clear();
|
||||
|
||||
appMgrServiceInner->RegisterConfigurationObserver(nullptr);
|
||||
appMgrServiceInner->RegisterConfigurationObserver(nullptr, -1);
|
||||
|
||||
sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
|
||||
appMgrServiceInner->RegisterConfigurationObserver(observer);
|
||||
appMgrServiceInner->RegisterConfigurationObserver(observer);
|
||||
appMgrServiceInner->RegisterConfigurationObserver(observer, -1);
|
||||
appMgrServiceInner->RegisterConfigurationObserver(observer, -1);
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "RegisterConfigurationObserver_001 end");
|
||||
}
|
||||
@@ -2899,7 +2899,7 @@ HWTEST_F(AppMgrServiceInnerTest, UnregisterConfigurationObserver_001, TestSize.L
|
||||
sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
|
||||
appMgrServiceInner->UnregisterConfigurationObserver(observer);
|
||||
|
||||
appMgrServiceInner->RegisterConfigurationObserver(observer);
|
||||
appMgrServiceInner->RegisterConfigurationObserver(observer, -1);
|
||||
appMgrServiceInner->UnregisterConfigurationObserver(observer);
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "UnregisterConfigurationObserver_001 end");
|
||||
|
||||
@@ -969,7 +969,7 @@ HWTEST_F(AppMgrServiceTest, RegisterConfigurationObserver_001, TestSize.Level2)
|
||||
auto appMgrService = std::make_shared<AppMgrService>();
|
||||
sptr<IConfigurationObserver> observer = nullptr;
|
||||
appMgrService->SetInnerService(nullptr);
|
||||
int32_t res = appMgrService->RegisterConfigurationObserver(observer);
|
||||
int32_t res = appMgrService->RegisterConfigurationObserver(observer, -1);
|
||||
EXPECT_EQ(res, ERR_INVALID_OPERATION);
|
||||
}
|
||||
|
||||
@@ -988,7 +988,7 @@ HWTEST_F(AppMgrServiceTest, RegisterConfigurationObserver_002, TestSize.Level2)
|
||||
appMgrService->SetInnerService(std::make_shared<AppMgrServiceInner>());
|
||||
appMgrService->taskHandler_ = taskHandler_;
|
||||
appMgrService->eventHandler_ = std::make_shared<AMSEventHandler>(taskHandler_, appMgrService->appMgrServiceInner_);
|
||||
int32_t res = appMgrService->RegisterConfigurationObserver(observer);
|
||||
int32_t res = appMgrService->RegisterConfigurationObserver(observer, -1);
|
||||
EXPECT_NE(res, ERR_INVALID_OPERATION);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,8 @@ public:
|
||||
MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId));
|
||||
MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name,
|
||||
int32_t appIndex));
|
||||
MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD2(RegisterConfigurationObserver,
|
||||
int32_t(const sptr<IConfigurationObserver>& observer, const int32_t userId));
|
||||
MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName));
|
||||
MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName,
|
||||
|
||||
+2
-1
@@ -75,7 +75,8 @@ public:
|
||||
MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId));
|
||||
MOCK_METHOD3(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name,
|
||||
int32_t appIndex));
|
||||
MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD2(RegisterConfigurationObserver,
|
||||
int32_t(const sptr<IConfigurationObserver>& observer, const int32_t userId));
|
||||
MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName));
|
||||
MOCK_METHOD2(NotifyLoadRepairPatch, int32_t(const std::string& bundleName,
|
||||
|
||||
Reference in New Issue
Block a user