mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
支持多用户配置
Signed-off-by: wlh2624 <1968860844@qq.com> Change-Id: Ib3afab79eff435deb84ca3713c799f2e83067f25
This commit is contained in:
@@ -351,7 +351,7 @@ public:
|
||||
* @param config System environment change parameters.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
virtual AppMgrResultCode UpdateConfiguration(const Configuration &config);
|
||||
virtual AppMgrResultCode UpdateConfiguration(const Configuration &config, const int32_t userId = -1);
|
||||
|
||||
/**
|
||||
* Update config by bundle name.
|
||||
|
||||
@@ -373,7 +373,7 @@ public:
|
||||
|
||||
virtual int32_t GetConfiguration(Configuration& config) = 0;
|
||||
|
||||
virtual int32_t UpdateConfiguration(const Configuration &config) = 0;
|
||||
virtual int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1) = 0;
|
||||
|
||||
virtual int32_t UpdateConfigurationByBundleName(const Configuration &config, const std::string &name) = 0;
|
||||
|
||||
|
||||
@@ -377,7 +377,7 @@ public:
|
||||
|
||||
virtual int32_t GetConfiguration(Configuration& config) override;
|
||||
|
||||
virtual int32_t UpdateConfiguration(const Configuration &config) override;
|
||||
virtual int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1) override;
|
||||
|
||||
virtual int32_t UpdateConfigurationByBundleName(const Configuration &config, const std::string &name) override;
|
||||
|
||||
|
||||
@@ -690,13 +690,13 @@ void AppMgrClient::ScheduleAcceptWantDone(const int32_t recordId, const AAFwk::W
|
||||
service->ScheduleAcceptWantDone(recordId, want, flag);
|
||||
}
|
||||
|
||||
AppMgrResultCode AppMgrClient::UpdateConfiguration(const Configuration &config)
|
||||
AppMgrResultCode AppMgrClient::UpdateConfiguration(const Configuration &config, const int32_t userId)
|
||||
{
|
||||
sptr<IAppMgr> service = iface_cast<IAppMgr>(mgrHolder_->GetRemoteObject());
|
||||
if (service == nullptr) {
|
||||
return AppMgrResultCode::ERROR_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
service->UpdateConfiguration(config);
|
||||
service->UpdateConfiguration(config, userId);
|
||||
return AppMgrResultCode::RESULT_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -840,7 +840,7 @@ int AppMgrProxy::GetRenderProcessTerminationStatus(pid_t renderPid, int &status)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AppMgrProxy::UpdateConfiguration(const Configuration &config)
|
||||
int32_t AppMgrProxy::UpdateConfiguration(const Configuration &config, const int32_t userId)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "AppMgrProxy UpdateConfiguration");
|
||||
MessageParcel data;
|
||||
@@ -853,6 +853,10 @@ int32_t AppMgrProxy::UpdateConfiguration(const Configuration &config)
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "parcel config failed");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
if (!data.WriteInt32(userId)) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "parcel userId failed");
|
||||
return ERR_INVALID_DATA;
|
||||
}
|
||||
int32_t ret = SendRequest(AppMgrInterfaceCode::UPDATE_CONFIGURATION, data, reply, option);
|
||||
if (ret != NO_ERROR) {
|
||||
TAG_LOGW(AAFwkTag::APPMGR, "SendRequest is failed, error code: %{public}d", ret);
|
||||
@@ -886,7 +890,7 @@ int32_t AppMgrProxy::UpdateConfigurationByBundleName(const Configuration &config
|
||||
return reply.ReadInt32();
|
||||
}
|
||||
|
||||
int32_t AppMgrProxy::GetConfiguration(Configuration &config)
|
||||
int32_t AppMgrProxy::GetConfiguration(Configuration& config)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
@@ -910,7 +914,7 @@ 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)
|
||||
{
|
||||
if (!observer) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "observer null");
|
||||
@@ -929,8 +933,7 @@ int32_t AppMgrProxy::RegisterConfigurationObserver(const sptr<IConfigurationObse
|
||||
return ERR_FLATTEN_OBJECT;
|
||||
}
|
||||
|
||||
auto error = SendRequest(AppMgrInterfaceCode::REGISTER_CONFIGURATION_OBSERVER,
|
||||
data, reply, option);
|
||||
auto error = SendRequest(AppMgrInterfaceCode::REGISTER_CONFIGURATION_OBSERVER, data, reply, option);
|
||||
if (error != NO_ERROR) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "Send request error: %{public}d", error);
|
||||
return error;
|
||||
|
||||
@@ -888,7 +888,8 @@ int32_t AppMgrStub::HandleUpdateConfiguration(MessageParcel &data, MessageParcel
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "AppMgrStub read configuration error");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
int32_t ret = UpdateConfiguration(*config);
|
||||
int32_t userId = data.ReadInt32();
|
||||
int32_t ret = UpdateConfiguration(*config, userId);
|
||||
if (!reply.WriteInt32(ret)) {
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
@@ -330,7 +330,7 @@ public:
|
||||
|
||||
virtual int32_t GetConfiguration(Configuration& config) override;
|
||||
|
||||
virtual int32_t UpdateConfiguration(const Configuration &config) override;
|
||||
virtual int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1) override;
|
||||
|
||||
virtual int32_t UpdateConfigurationByBundleName(const Configuration &config, const std::string &name) override;
|
||||
|
||||
|
||||
@@ -86,6 +86,15 @@ constexpr int32_t BASE_USER_RANGE = 200000;
|
||||
|
||||
class AppMgrServiceInner : public std::enable_shared_from_this<AppMgrServiceInner> {
|
||||
public:
|
||||
struct ConfigurationObserverWithUserId {
|
||||
sptr<IConfigurationObserver> observer;
|
||||
int32_t userId = -1;
|
||||
};
|
||||
struct AppStateCallbackWithUserId {
|
||||
sptr<IAppStateCallback> callback;
|
||||
int32_t userId = -1;
|
||||
};
|
||||
|
||||
AppMgrServiceInner();
|
||||
virtual ~AppMgrServiceInner();
|
||||
|
||||
@@ -619,7 +628,7 @@ public:
|
||||
* @param config, System environment change parameters.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t UpdateConfiguration(const Configuration &config);
|
||||
int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1);
|
||||
|
||||
int32_t UpdateConfigurationByBundleName(const Configuration &config, const std::string &name);
|
||||
|
||||
@@ -1489,7 +1498,7 @@ private:
|
||||
void SendReStartProcessEvent(AAFwk::EventInfo &eventInfo, int32_t appUid);
|
||||
void SendAppLaunchEvent(const std::shared_ptr<AppRunningRecord> &appRecord);
|
||||
void InitAppWaitingDebugList();
|
||||
void HandleConfigurationChange(const Configuration &config);
|
||||
void HandleConfigurationChange(const Configuration &config, const int32_t userId = -1);
|
||||
bool CheckIsThreadInFoundation(pid_t pid);
|
||||
bool CheckAppFault(const std::shared_ptr<AppRunningRecord> &appRecord, const FaultData &faultData);
|
||||
int32_t KillFaultApp(int32_t pid, const std::string &bundleName, const FaultData &faultData,
|
||||
@@ -1505,7 +1514,7 @@ private:
|
||||
void MakeIsolateSandBoxProcessName(const std::shared_ptr<AbilityInfo> &abilityInfo,
|
||||
const HapModuleInfo &hapModuleInfo, std::string &processName) const;
|
||||
const std::string TASK_ON_CALLBACK_DIED = "OnCallbackDiedTask";
|
||||
std::vector<sptr<IAppStateCallback>> appStateCallbacks_;
|
||||
std::vector<AppStateCallbackWithUserId> appStateCallbacks_;
|
||||
std::shared_ptr<RemoteClientManager> remoteClientManager_;
|
||||
std::shared_ptr<AppRunningManager> appRunningManager_;
|
||||
std::shared_ptr<AAFwk::TaskHandlerWrap> taskHandler_;
|
||||
@@ -1518,7 +1527,8 @@ private:
|
||||
ffrt::mutex browserHostLock_;
|
||||
sptr<IStartSpecifiedAbilityResponse> startSpecifiedAbilityResponse_;
|
||||
ffrt::mutex configurationObserverLock_;
|
||||
std::vector<sptr<IConfigurationObserver>> configurationObservers_;
|
||||
std::vector<ConfigurationObserverWithUserId> configurationObservers_;
|
||||
|
||||
#ifdef SUPPORT_SCREEN
|
||||
sptr<WindowFocusChangedListener> focusListener_;
|
||||
sptr<WindowVisibilityChangedListener> windowVisibilityChangedListener_;
|
||||
@@ -1548,7 +1558,9 @@ private:
|
||||
|
||||
std::mutex loadTaskListMutex_;
|
||||
std::vector<LoadAbilityTaskFunc> loadAbilityTaskFuncList_;
|
||||
|
||||
std::shared_ptr<MultiUserConfigurationMgr> multiUserConfigurationMgr_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H
|
||||
#endif // OHOS_ABILITY_RUNTIME_APP_MGR_SERVICE_INNER_H
|
||||
|
||||
@@ -41,6 +41,7 @@ namespace Rosen {
|
||||
class WindowVisibilityInfo;
|
||||
}
|
||||
namespace AppExecFwk {
|
||||
|
||||
class AppRunningManager {
|
||||
public:
|
||||
AppRunningManager();
|
||||
@@ -183,7 +184,7 @@ public:
|
||||
* @param config System environment change parameters.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t UpdateConfiguration(const Configuration &config);
|
||||
int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1);
|
||||
|
||||
/**
|
||||
* Update config by sa.
|
||||
@@ -346,7 +347,9 @@ public:
|
||||
|
||||
bool HandleUserRequestClean(const sptr<IRemoteObject> &abilityToken, pid_t &pid, int32_t &uid);
|
||||
|
||||
private:
|
||||
void SetMultiUserConfigurationMgr(const std::shared_ptr<MultiUserConfigurationMgr>& multiUserConfigurationMgr);
|
||||
|
||||
private:
|
||||
std::shared_ptr<AbilityRunningRecord> GetAbilityRunningRecord(const int64_t eventId);
|
||||
int32_t AssignRunningProcessInfoByAppRecord(
|
||||
std::shared_ptr<AppRunningRecord> appRecord, AppExecFwk::RunningProcessInfo &info) const;
|
||||
@@ -362,6 +365,7 @@ private:
|
||||
std::shared_ptr<Configuration> configuration_;
|
||||
std::mutex updateConfigurationDelayedLock_;
|
||||
std::map<const int32_t, bool> updateConfigurationDelayedMap_;
|
||||
std::shared_ptr<MultiUserConfigurationMgr> multiUserConfigurationMgr_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -54,6 +54,17 @@ class AbilityRunningRecord;
|
||||
class AppMgrServiceInner;
|
||||
class AppRunningRecord;
|
||||
|
||||
class MultiUserConfigurationMgr {
|
||||
public:
|
||||
void Insert(const int32_t userId, const Configuration& config);
|
||||
|
||||
Configuration GetConfigurationByUserId(const int32_t userId);
|
||||
|
||||
private:
|
||||
std::map<int32_t, Configuration> multiUserConfiguration_;
|
||||
std::mutex multiUserConfigurationMutex_;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class RenderRecord
|
||||
* Record nweb render process info.
|
||||
|
||||
@@ -997,14 +997,14 @@ int32_t AppMgrService::GetConfiguration(Configuration& config)
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
int32_t AppMgrService::UpdateConfiguration(const Configuration& config)
|
||||
int32_t AppMgrService::UpdateConfiguration(const Configuration& config, const int32_t userId)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
if (!IsReady()) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "UpdateConfiguration failed, AppMgrService not ready.");
|
||||
return ERR_INVALID_OPERATION;
|
||||
}
|
||||
return appMgrServiceInner_->UpdateConfiguration(config);
|
||||
return appMgrServiceInner_->UpdateConfiguration(config, userId);
|
||||
}
|
||||
|
||||
int32_t AppMgrService::UpdateConfigurationByBundleName(const Configuration& config, const std::string &name)
|
||||
|
||||
@@ -178,8 +178,6 @@ constexpr const char* RENDER_PROCESS_NAME = ":render";
|
||||
constexpr const char* RENDER_PROCESS_TYPE = "render";
|
||||
constexpr const char* GPU_PROCESS_NAME = ":gpu";
|
||||
constexpr const char* GPU_PROCESS_TYPE = "gpu";
|
||||
constexpr const char* FONT_WGHT_SCALE = "persist.sys.font_wght_scale_for_user0";
|
||||
constexpr const char* FONT_SCALE = "persist.sys.font_scale_for_user0";
|
||||
constexpr const char* KILL_REASON_USER_REQUEST = "User Request";
|
||||
const std::string TOKEN_ID = "TOKEN_ID";
|
||||
const int32_t SIGNAL_KILL = 9;
|
||||
@@ -294,8 +292,11 @@ AppMgrServiceInner::AppMgrServiceInner()
|
||||
appDebugManager_(std::make_shared<AppDebugManager>()),
|
||||
appRunningStatusModule_(std::make_shared<AbilityRuntime::AppRunningStatusModule>()),
|
||||
securityModeManager_(std::make_shared<AdvancedSecurityModeManager>()),
|
||||
appPreloader_(std::make_shared<AppPreloader>(remoteClientManager_))
|
||||
{}
|
||||
appPreloader_(std::make_shared<AppPreloader>(remoteClientManager_)),
|
||||
multiUserConfigurationMgr_(std::make_shared<MultiUserConfigurationMgr>())
|
||||
{
|
||||
appRunningManager_->SetMultiUserConfigurationMgr(multiUserConfigurationMgr_);
|
||||
}
|
||||
|
||||
void AppMgrServiceInner::Init()
|
||||
{
|
||||
@@ -929,9 +930,9 @@ void AppMgrServiceInner::NotifyAppAttachFailed(std::shared_ptr<AppRunningRecord>
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "Attach failed name: %{public}s %{public}zu", appRecord->GetProcessName().c_str(),
|
||||
abilityTokens.size());
|
||||
std::lock_guard lock(appStateCallbacksLock_);
|
||||
for (const auto &callback : appStateCallbacks_) {
|
||||
if (callback != nullptr) {
|
||||
callback->OnAppRemoteDied(abilityTokens);
|
||||
for (const auto &item : appStateCallbacks_) {
|
||||
if (item.callback != nullptr) {
|
||||
item.callback->OnAppRemoteDied(abilityTokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -963,6 +964,13 @@ void AppMgrServiceInner::LaunchApplication(const std::shared_ptr<AppRunningRecor
|
||||
return;
|
||||
}
|
||||
|
||||
if (int32_t userId = appRecord->GetUid() / BASE_USER_RANGE; userId != 0) {
|
||||
auto config = multiUserConfigurationMgr_->GetConfigurationByUserId(userId);
|
||||
std::vector<std::string> diffVe;
|
||||
configuration_->CompareDifferent(diffVe, config);
|
||||
configuration_->Merge(diffVe, config);
|
||||
}
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "LaunchApplication configuration:%{public}s", configuration_->GetName().c_str());
|
||||
appRecord->LaunchApplication(*configuration_);
|
||||
appRecord->SetState(ApplicationState::APP_STATE_READY);
|
||||
int restartResidentProcCount = MAX_RESTART_COUNT;
|
||||
@@ -2245,16 +2253,17 @@ void AppMgrServiceInner::SetBundleManagerHelper(const std::shared_ptr<BundleMgrH
|
||||
remoteClientManager_->SetBundleManagerHelper(bundleMgrHelper);
|
||||
}
|
||||
|
||||
void AppMgrServiceInner::RegisterAppStateCallback(const sptr<IAppStateCallback> &callback)
|
||||
void AppMgrServiceInner::RegisterAppStateCallback(const sptr<IAppStateCallback>& callback)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
if (callback != nullptr) {
|
||||
std::lock_guard lock(appStateCallbacksLock_);
|
||||
appStateCallbacks_.push_back(callback);
|
||||
appStateCallbacks_.push_back(
|
||||
AppStateCallbackWithUserId { callback, GetUserIdByUid(IPCSkeleton::GetCallingUid()) });
|
||||
auto remoteObjedct = callback->AsObject();
|
||||
if (remoteObjedct) {
|
||||
remoteObjedct->AddDeathRecipient(sptr<AppStateCallbackDeathRecipient>(
|
||||
new AppStateCallbackDeathRecipient(weak_from_this())));
|
||||
remoteObjedct->AddDeathRecipient(
|
||||
sptr<AppStateCallbackDeathRecipient>(new AppStateCallbackDeathRecipient(weak_from_this())));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2269,7 +2278,7 @@ void AppMgrServiceInner::RemoveDeadAppStateCallback(const wptr<IRemoteObject> &r
|
||||
|
||||
std::lock_guard lock(appStateCallbacksLock_);
|
||||
for (auto it = appStateCallbacks_.begin(); it != appStateCallbacks_.end(); ++it) {
|
||||
auto callback = *it;
|
||||
auto callback = (*it).callback;
|
||||
if (callback && callback->AsObject() == remoteObject) {
|
||||
appStateCallbacks_.erase(it);
|
||||
break;
|
||||
@@ -2534,9 +2543,9 @@ void AppMgrServiceInner::OnAppStateChanged(
|
||||
appRecord->GetBundleName().c_str(), static_cast<int32_t>(state));
|
||||
{
|
||||
std::lock_guard lock(appStateCallbacksLock_);
|
||||
for (const auto &callback : appStateCallbacks_) {
|
||||
if (callback != nullptr) {
|
||||
callback->OnAppStateChanged(WrapAppProcessData(appRecord, state));
|
||||
for (const auto &item : appStateCallbacks_) {
|
||||
if (item.callback != nullptr) {
|
||||
item.callback->OnAppStateChanged(WrapAppProcessData(appRecord, state));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2619,9 +2628,9 @@ void AppMgrServiceInner::OnAbilityStateChanged(
|
||||
return;
|
||||
}
|
||||
std::lock_guard lock(appStateCallbacksLock_);
|
||||
for (const auto &callback : appStateCallbacks_) {
|
||||
if (callback != nullptr) {
|
||||
callback->OnAbilityRequestDone(ability->GetToken(), state);
|
||||
for (const auto &item : appStateCallbacks_) {
|
||||
if (item.callback != nullptr) {
|
||||
item.callback->OnAbilityRequestDone(ability->GetToken(), state);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3278,9 +3287,9 @@ void AppMgrServiceInner::OnRemoteDied(const wptr<IRemoteObject> &remote, bool is
|
||||
for (const auto &token : appRecord->GetAbilities()) {
|
||||
abilityTokens.emplace_back(token.first);
|
||||
}
|
||||
for (const auto &callback : appStateCallbacks_) {
|
||||
if (callback != nullptr) {
|
||||
callback->OnAppRemoteDied(abilityTokens);
|
||||
for (const auto &item : appStateCallbacks_) {
|
||||
if (item.callback != nullptr) {
|
||||
item.callback->OnAppRemoteDied(abilityTokens);
|
||||
}
|
||||
}
|
||||
ClearData(appRecord);
|
||||
@@ -4158,8 +4167,11 @@ void AppMgrServiceInner::HandleStartSpecifiedProcessTimeout(const int64_t eventI
|
||||
appRecord->ResetNewProcessRequestId();
|
||||
}
|
||||
|
||||
int32_t AppMgrServiceInner::UpdateConfiguration(const Configuration &config)
|
||||
int32_t AppMgrServiceInner::UpdateConfiguration(const Configuration &config, const int32_t userId)
|
||||
{
|
||||
if (userId != -1) {
|
||||
multiUserConfigurationMgr_->Insert(userId, config);
|
||||
}
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
if (!appRunningManager_) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "appRunningManager_ is null");
|
||||
@@ -4186,19 +4198,20 @@ int32_t AppMgrServiceInner::UpdateConfiguration(const Configuration &config)
|
||||
configuration_->Merge(changeKeyV, config);
|
||||
}
|
||||
// all app
|
||||
int32_t result = appRunningManager_->UpdateConfiguration(config);
|
||||
HandleConfigurationChange(config);
|
||||
int32_t result = appRunningManager_->UpdateConfiguration(config, userId);
|
||||
HandleConfigurationChange(config, userId);
|
||||
if (result != ERR_OK) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "update error, not notify");
|
||||
return result;
|
||||
}
|
||||
// notify
|
||||
std::lock_guard<ffrt::mutex> notifyLock(configurationObserverLock_);
|
||||
for (auto &observer : configurationObservers_) {
|
||||
if (observer != nullptr) {
|
||||
observer->OnConfigurationUpdated(config);
|
||||
for (auto &item : configurationObservers_) {
|
||||
if (item.observer != nullptr && (userId == -1 || item.userId == 0 || item.userId == userId)) {
|
||||
item.observer->OnConfigurationUpdated(config);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -4221,13 +4234,14 @@ int32_t AppMgrServiceInner::UpdateConfigurationByBundleName(const Configuration
|
||||
return result;
|
||||
}
|
||||
|
||||
void AppMgrServiceInner::HandleConfigurationChange(const Configuration &config)
|
||||
void AppMgrServiceInner::HandleConfigurationChange(const Configuration& config, const int32_t userId)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
std::lock_guard lock(appStateCallbacksLock_);
|
||||
for (const auto &callback : appStateCallbacks_) {
|
||||
if (callback != nullptr) {
|
||||
callback->NotifyConfigurationChange(config, currentUserId_);
|
||||
|
||||
for (const auto &item : appStateCallbacks_) {
|
||||
if (item.callback != nullptr && (userId == -1 || item.userId == 0 || item.userId == userId)) {
|
||||
item.callback->NotifyConfigurationChange(config, currentUserId_);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4246,14 +4260,15 @@ int32_t AppMgrServiceInner::RegisterConfigurationObserver(const sptr<IConfigurat
|
||||
}
|
||||
std::lock_guard<ffrt::mutex> registerLock(configurationObserverLock_);
|
||||
auto it = std::find_if(configurationObservers_.begin(), configurationObservers_.end(),
|
||||
[&observer](const sptr<IConfigurationObserver> &item) {
|
||||
return (item && item->AsObject() == observer->AsObject());
|
||||
[&observer](const ConfigurationObserverWithUserId& item) {
|
||||
return (item.observer && item.observer->AsObject() == observer->AsObject());
|
||||
});
|
||||
if (it != configurationObservers_.end()) {
|
||||
TAG_LOGE(AAFwkTag::APPMGR, "AppMgrServiceInner::Register error: observer exist");
|
||||
return ERR_INVALID_VALUE;
|
||||
}
|
||||
configurationObservers_.push_back(observer);
|
||||
configurationObservers_.push_back(
|
||||
ConfigurationObserverWithUserId { observer, GetUserIdByUid(IPCSkeleton::GetCallingUid()) });
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
@@ -4270,8 +4285,8 @@ int32_t AppMgrServiceInner::UnregisterConfigurationObserver(const sptr<IConfigur
|
||||
}
|
||||
std::lock_guard<ffrt::mutex> unregisterLock(configurationObserverLock_);
|
||||
auto it = std::find_if(configurationObservers_.begin(), configurationObservers_.end(),
|
||||
[&observer](const sptr<IConfigurationObserver> &item) {
|
||||
return (item && item->AsObject() == observer->AsObject());
|
||||
[&observer](const ConfigurationObserverWithUserId &item) {
|
||||
return (item.observer && item.observer->AsObject() == observer->AsObject());
|
||||
});
|
||||
if (it != configurationObservers_.end()) {
|
||||
configurationObservers_.erase(it);
|
||||
@@ -4308,12 +4323,8 @@ void AppMgrServiceInner::InitGlobalConfiguration()
|
||||
auto deviceType = GetDeviceType();
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "current deviceType is %{public}s", deviceType);
|
||||
configuration_->AddItem(AAFwk::GlobalConfigurationKey::DEVICE_TYPE, deviceType);
|
||||
auto fontSizeScale = OHOS::system::GetParameter(FONT_SCALE, "1.0");
|
||||
auto fontWeightScale = OHOS::system::GetParameter(FONT_WGHT_SCALE, "1.0");
|
||||
TAG_LOGI(AAFwkTag::APPMGR, "current fontSizeScale is: %{public}s, fontWeightScale is: %{public}s",
|
||||
fontSizeScale.c_str(), fontWeightScale.c_str());
|
||||
configuration_->AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_SIZE_SCALE, fontSizeScale);
|
||||
configuration_->AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_WEIGHT_SCALE, fontWeightScale);
|
||||
configuration_->AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_SIZE_SCALE, "1.0");
|
||||
configuration_->AddItem(AAFwk::GlobalConfigurationKey::SYSTEM_FONT_WEIGHT_SCALE, "1.0");
|
||||
}
|
||||
|
||||
std::shared_ptr<AppExecFwk::Configuration> AppMgrServiceInner::GetConfiguration()
|
||||
@@ -5088,7 +5099,6 @@ void AppMgrServiceInner::HandleUnfocused(const sptr<OHOS::Rosen::FocusChangeInfo
|
||||
DelayedSingleton<AppStateObserverManager>::GetInstance()->OnProcessStateChanged(appRecord);
|
||||
}
|
||||
|
||||
|
||||
void AppMgrServiceInner::InitWindowVisibilityChangedListener()
|
||||
{
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "Begin.");
|
||||
@@ -7047,9 +7057,9 @@ bool AppMgrServiceInner::IsMemorySizeSufficent()
|
||||
void AppMgrServiceInner::NotifyStartResidentProcess(std::vector<AppExecFwk::BundleInfo> &bundleInfos)
|
||||
{
|
||||
std::lock_guard lock(appStateCallbacksLock_);
|
||||
for (const auto &callback : appStateCallbacks_) {
|
||||
if (callback != nullptr) {
|
||||
callback->NotifyStartResidentProcess(bundleInfos);
|
||||
for (const auto &item : appStateCallbacks_) {
|
||||
if (item.callback != nullptr) {
|
||||
item.callback->NotifyStartResidentProcess(bundleInfos);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7515,4 +7525,4 @@ int32_t AppMgrServiceInner::GetSupportedProcessCachePids(const std::string &bund
|
||||
return ERR_OK;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -779,8 +779,7 @@ void AppRunningManager::GetForegroundApplications(std::vector<AppStateData> &lis
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t AppRunningManager::UpdateConfiguration(const Configuration &config)
|
||||
int32_t AppRunningManager::UpdateConfiguration(const Configuration& config, const int32_t userId)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
|
||||
std::vector<std::string> changeKeyV;
|
||||
@@ -792,12 +791,16 @@ int32_t AppRunningManager::UpdateConfiguration(const Configuration &config)
|
||||
auto appRunningMap = GetAppRunningRecordMap();
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "current app size %{public}zu", appRunningMap.size());
|
||||
int32_t result = ERR_OK;
|
||||
for (const auto &item : appRunningMap) {
|
||||
const auto &appRecord = item.second;
|
||||
for (const auto& item : appRunningMap) {
|
||||
const auto& appRecord = item.second;
|
||||
if (appRecord && appRecord->GetState() == ApplicationState::APP_STATE_CREATE) {
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "app not ready, appName is %{public}s", appRecord->GetBundleName().c_str());
|
||||
continue;
|
||||
}
|
||||
if (!(userId == -1 || appRecord->GetUid() / BASE_USER_RANGE == 0 ||
|
||||
appRecord->GetUid() / BASE_USER_RANGE == userId)) {
|
||||
continue;
|
||||
}
|
||||
if (appRecord && !isCollaboratorReserveType(appRecord)) {
|
||||
TAG_LOGD(AAFwkTag::APPMGR, "Notification app [%{public}s]", appRecord->GetName().c_str());
|
||||
std::lock_guard guard(updateConfigurationDelayedLock_);
|
||||
@@ -1619,16 +1622,29 @@ bool AppRunningManager::IsAppProcessesAllCached(const std::string &bundleName, i
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t AppRunningManager::UpdateConfigurationDelayed(const std::shared_ptr<AppRunningRecord> &appRecord)
|
||||
int32_t AppRunningManager::UpdateConfigurationDelayed(const std::shared_ptr<AppRunningRecord>& appRecord)
|
||||
{
|
||||
std::lock_guard guard(updateConfigurationDelayedLock_);
|
||||
int32_t result = ERR_OK;
|
||||
auto it = updateConfigurationDelayedMap_.find(appRecord->GetRecordId());
|
||||
if (it != updateConfigurationDelayedMap_.end() && it->second) {
|
||||
int32_t userId = appRecord->GetUid() / BASE_USER_RANGE;
|
||||
if (userId != 0) {
|
||||
auto config = multiUserConfigurationMgr_->GetConfigurationByUserId(userId);
|
||||
std::vector<std::string> diffVe;
|
||||
configuration_->CompareDifferent(diffVe, config);
|
||||
configuration_->Merge(diffVe, config);
|
||||
}
|
||||
result = appRecord->UpdateConfiguration(*configuration_);
|
||||
it->second = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void AppRunningManager::SetMultiUserConfigurationMgr(
|
||||
const std::shared_ptr<MultiUserConfigurationMgr>& multiUserConfigurationMgr)
|
||||
{
|
||||
multiUserConfigurationMgr_ = multiUserConfigurationMgr;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -200,6 +200,29 @@ int32_t RenderRecord::GetState() const
|
||||
return state_;
|
||||
}
|
||||
|
||||
void MultiUserConfigurationMgr::Insert(const int32_t userId, const Configuration& config)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(multiUserConfigurationMutex_);
|
||||
auto it = multiUserConfiguration_.find(userId);
|
||||
if (it != multiUserConfiguration_.end()) {
|
||||
std::vector<std::string> diffVe;
|
||||
it->second.CompareDifferent(diffVe, config);
|
||||
it->second.Merge(diffVe, config);
|
||||
} else {
|
||||
multiUserConfiguration_[userId] = config;
|
||||
}
|
||||
}
|
||||
|
||||
Configuration MultiUserConfigurationMgr::GetConfigurationByUserId(const int32_t userId)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(multiUserConfigurationMutex_);
|
||||
auto it = multiUserConfiguration_.find(userId);
|
||||
if (it == multiUserConfiguration_.end()) {
|
||||
return {};
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
AppRunningRecord::AppRunningRecord(
|
||||
const std::shared_ptr<ApplicationInfo> &info, const int32_t recordId, const std::string &processName)
|
||||
: appRecordId_(recordId), processName_(processName)
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
MOCK_METHOD1(SaveBrowserChannel, void(sptr<IRemoteObject> browser));
|
||||
MOCK_METHOD2(GetRenderProcessTerminationStatus, int(pid_t renderPid, int& status));
|
||||
MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config));
|
||||
MOCK_METHOD1(UpdateConfiguration, int32_t(const Configuration& config));
|
||||
MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId));
|
||||
MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD1(GetAppRunningStateByBundleName, bool(const std::string& bundleName));
|
||||
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
void(const int32_t recordId, const AAFwk::Want& want, const std::string& flag));
|
||||
MOCK_METHOD2(GetAbilityRecordsByProcessID, int(const int pid, std::vector<sptr<IRemoteObject>>& tokens));
|
||||
MOCK_METHOD1(GetConfiguration, int32_t(Configuration& config));
|
||||
MOCK_METHOD1(UpdateConfiguration, int32_t(const Configuration& config));
|
||||
MOCK_METHOD2(UpdateConfiguration, int32_t(const Configuration& config, const int32_t userId));
|
||||
MOCK_METHOD2(UpdateConfigurationByBundleName, int32_t(const Configuration& config, const std::string &name));
|
||||
MOCK_METHOD1(RegisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
MOCK_METHOD1(UnregisterConfigurationObserver, int32_t(const sptr<IConfigurationObserver>& observer));
|
||||
|
||||
@@ -1685,11 +1685,11 @@ HWTEST_F(AppMgrServiceInnerTest, OnAppStateChanged_001, TestSize.Level0)
|
||||
sptr<MockAppStateCallback> mockCallback(new MockAppStateCallback());
|
||||
EXPECT_CALL(*mockCallback, OnAppStateChanged(_)).Times(2);
|
||||
sptr<IAppStateCallback> callback1 = iface_cast<IAppStateCallback>(mockCallback);
|
||||
appMgrServiceInner->appStateCallbacks_.push_back(callback1);
|
||||
appMgrServiceInner->appStateCallbacks_.push_back({ callback1, 100 });
|
||||
appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true, false);
|
||||
|
||||
sptr<IAppStateCallback> callback;
|
||||
appMgrServiceInner->appStateCallbacks_.push_back(callback);
|
||||
appMgrServiceInner->appStateCallbacks_.push_back({ callback, 100 });
|
||||
appMgrServiceInner->OnAppStateChanged(appRecord, ApplicationState::APP_STATE_CREATE, true, false);
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "OnAppStateChanged_001 end");
|
||||
@@ -1717,11 +1717,11 @@ HWTEST_F(AppMgrServiceInnerTest, OnAbilityStateChanged_001, TestSize.Level0)
|
||||
sptr<MockAppStateCallback> mockCallback(new MockAppStateCallback());
|
||||
EXPECT_CALL(*mockCallback, OnAbilityRequestDone(_, _)).Times(2);
|
||||
sptr<IAppStateCallback> callback1 = iface_cast<IAppStateCallback>(mockCallback);
|
||||
appMgrServiceInner->appStateCallbacks_.push_back(callback1);
|
||||
appMgrServiceInner->appStateCallbacks_.push_back({ callback1, 100 });
|
||||
appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
|
||||
|
||||
sptr<IAppStateCallback> callback;
|
||||
appMgrServiceInner->appStateCallbacks_.push_back(callback);
|
||||
appMgrServiceInner->appStateCallbacks_.push_back({ callback, 100 });
|
||||
appMgrServiceInner->OnAbilityStateChanged(abilityRunningRecord, AbilityState::ABILITY_STATE_CREATE);
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "OnAbilityStateChanged_001 end");
|
||||
@@ -2639,10 +2639,10 @@ HWTEST_F(AppMgrServiceInnerTest, UpdateConfiguration_001, TestSize.Level0)
|
||||
appMgrServiceInner->UpdateConfiguration(config);
|
||||
|
||||
sptr<MockConfigurationObserver> observer(new (std::nothrow) MockConfigurationObserver());
|
||||
appMgrServiceInner->configurationObservers_.push_back(observer);
|
||||
appMgrServiceInner->configurationObservers_.push_back({ observer, 100 });
|
||||
sptr<IConfigurationObserver> observer1;
|
||||
appMgrServiceInner->configurationObservers_.push_back(observer1);
|
||||
appMgrServiceInner->configurationObservers_.push_back(nullptr);
|
||||
appMgrServiceInner->configurationObservers_.push_back({ observer1, 100 });
|
||||
appMgrServiceInner->configurationObservers_.push_back({ nullptr, 100 });
|
||||
appMgrServiceInner->UpdateConfiguration(config);
|
||||
|
||||
appMgrServiceInner->appRunningManager_ = nullptr;
|
||||
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
const AAFwk::Want &want, const sptr<IRemoteObject> &observer, const BundleInfo &bundleInfo, int32_t userId));
|
||||
MOCK_METHOD3(FinishUserTest, int(
|
||||
const std::string &msg, const int64_t &resultCode, const std::string &bundleName));
|
||||
MOCK_METHOD1(UpdateConfiguration, AppMgrResultCode(const Configuration &config));
|
||||
MOCK_METHOD2(UpdateConfiguration, AppMgrResultCode(const Configuration &config, const int32_t userId));
|
||||
MOCK_METHOD1(GetConfiguration, AppMgrResultCode(Configuration& config));
|
||||
MOCK_METHOD2(GetAbilityRecordsByProcessID, int(
|
||||
const int pid, std::vector<sptr<IRemoteObject>> &tokens));
|
||||
|
||||
@@ -973,7 +973,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_FinishUserTest_002, TestSize.Level1)
|
||||
*/
|
||||
HWTEST_F(AppSchedulerTest, AppScheduler_UpdateConfiguration_001, TestSize.Level1)
|
||||
{
|
||||
EXPECT_CALL(*clientMock_, UpdateConfiguration(_)).Times(1)
|
||||
EXPECT_CALL(*clientMock_, UpdateConfiguration(_, _)).Times(1)
|
||||
.WillOnce(Return(AppMgrResultCode::RESULT_OK));
|
||||
DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
|
||||
AppExecFwk::Configuration config;
|
||||
@@ -991,7 +991,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_UpdateConfiguration_001, TestSize.Level1
|
||||
*/
|
||||
HWTEST_F(AppSchedulerTest, AppScheduler_UpdateConfiguration_002, TestSize.Level1)
|
||||
{
|
||||
EXPECT_CALL(*clientMock_, UpdateConfiguration(_)).Times(1)
|
||||
EXPECT_CALL(*clientMock_, UpdateConfiguration(_, _)).Times(1)
|
||||
.WillOnce(Return(AppMgrResultCode::ERROR_SERVICE_NOT_READY));
|
||||
DelayedSingleton<AppScheduler>::GetInstance()->appMgrClient_ = std::move(clientMock_);
|
||||
AppExecFwk::Configuration config;
|
||||
|
||||
@@ -215,7 +215,7 @@ class MockAppMgrStub : public AppMgrStub {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t UpdateConfiguration(const Configuration &config) override
|
||||
int32_t UpdateConfiguration(const Configuration &config, const int32_t userId = -1) override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user