From 0315ee1c4ed8146ee7bccd36933aa984a674f059 Mon Sep 17 00:00:00 2001 From: njupthan Date: Mon, 10 Jan 2022 21:14:57 +0000 Subject: [PATCH 01/11] Cross-device information synchronization and query Signed-off-by: njupthan --- .../native/test/mock/include/bundle_mgr_interface.h | 4 ++++ .../native/test/mock/include/mock_bundle_manager.h | 6 ++++++ .../include/bundlemgr/bundle_mgr_interface.h | 4 ++++ .../include/bundlemgr/mock_bundle_manager.h | 6 ++++++ services/test/mock/include/mock_bundle_mgr.h | 9 ++++++++- 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h b/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h index cea500ac69b..9404f4d2f63 100644 --- a/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h +++ b/frameworks/kits/ability/native/test/mock/include/bundle_mgr_interface.h @@ -27,6 +27,7 @@ #include "ohos/aafwk/content/want.h" #include "permission_def.h" #include "module_usage_record.h" +#include "distributed_bundle_info.h" using OHOS::AAFwk::Want; @@ -228,6 +229,9 @@ public: virtual bool RemoveClonedBundle(const std::string &bundleName, const int32_t uid) = 0; virtual bool BundleClone(const std::string &bundleName) = 0; virtual bool CheckBundleNameInAllowList(const std::string &bundleName) = 0; + virtual bool GetDistributedBundleInfo( + const std::string &networkId, int32_t userId, const std::string &bundleName, + DistributedBundleInfo &distributedBundleInfo) = 0; enum class Message { GET_APPLICATION_INFO, diff --git a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h index 96c88016bae..e3ca26fdae5 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h @@ -205,6 +205,12 @@ public: { return true; } + virtual bool GetDistributedBundleInfo( + const std::string &networkId, int32_t userId, const std::string &bundleName, + DistributedBundleInfo &distributedBundleInfo) override + { + return true; + } }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h index adcaa9c71fd..648a2fa206d 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/bundle_mgr_interface.h @@ -31,6 +31,7 @@ #include "common_event_info.h" #include "on_permission_changed_callback_interface.h" #include "ohos/aafwk/content/want.h" +#include "distributed_bundle_info.h" namespace OHOS { namespace AppExecFwk { @@ -441,6 +442,9 @@ public: virtual bool RemoveClonedBundle(const std::string &bundleName, const int32_t uid) = 0; virtual bool BundleClone(const std::string &bundleName) = 0; virtual bool CheckBundleNameInAllowList(const std::string &bundleName) = 0; + virtual bool GetDistributedBundleInfo( + const std::string &networkId, int32_t userId, const std::string &bundleName, + DistributedBundleInfo &distributedBundleInfo) = 0; enum class Message { GET_APPLICATION_INFO, diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/mock_bundle_manager.h b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/mock_bundle_manager.h index 2eea64e4954..39bfacd9c50 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/mock_bundle_manager.h +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/mock_bundle_manager.h @@ -315,6 +315,12 @@ public: { return true; } + virtual bool GetDistributedBundleInfo( + const std::string &networkId, int32_t userId, const std::string &bundleName, + DistributedBundleInfo &distributedBundleInfo) override + { + return true; + } public: using QueryAbilityInfoFunType = diff --git a/services/test/mock/include/mock_bundle_mgr.h b/services/test/mock/include/mock_bundle_mgr.h index c3bfb9e307d..127a7b8be03 100644 --- a/services/test/mock/include/mock_bundle_mgr.h +++ b/services/test/mock/include/mock_bundle_mgr.h @@ -258,6 +258,8 @@ public: MOCK_METHOD2(GetShortcutInfos, bool(const std::string &bundleName, std::vector &shortcutInfos)); MOCK_METHOD2(QueryAbilityInfos, bool(const Want &want, std::vector &abilityInfos)); MOCK_METHOD2(QueryAbilityInfosForClone, bool(const Want &want, std::vector &abilityInfos)); + MOCK_METHOD4(GetDistributedBundleInfo, bool(const std::string &networkId, int32_t userId, + const std::string &bundleName, DistributedBundleInfo &distributedBundleInfo)); }; class BundleMgrStub : public IRemoteStub { @@ -373,7 +375,12 @@ public: { return true; } - + virtual bool GetDistributedBundleInfo( + const std::string &networkId, int32_t userId, const std::string &bundleName, + DistributedBundleInfo &distributedBundleInfo) override + { + return true; + } BundleMgrService() { abilityInfoMap_.emplace(COM_IX_HIWORLD, HiWordInfo); -- Gitee From 7776e6959693a0af7fb310eb167f0faa2efdc91a Mon Sep 17 00:00:00 2001 From: njupthan Date: Tue, 11 Jan 2022 11:19:18 +0000 Subject: [PATCH 02/11] Fix codex Signed-off-by: njupthan --- .../ability/native/test/mock/include/mock_bundle_manager.h | 6 ++++-- .../appexecfwk_core/include/bundlemgr/mock_bundle_manager.h | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h index e3ca26fdae5..8ab2ec5c246 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.h @@ -98,7 +98,8 @@ public: const int32_t number, std::vector &moduleUsageRecords) override; virtual sptr GetBundleInstaller() override; virtual bool NotifyAbilityLifeStatus( - const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) override; + const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) + override; }; class BundleMgrStub : public IRemoteStub { @@ -174,7 +175,8 @@ public: const int32_t number, std::vector &moduleUsageRecords) override; virtual sptr GetBundleInstaller() override; virtual bool NotifyAbilityLifeStatus( - const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) override; + const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) + override; virtual bool GetBundleGidsByUid(const std::string &bundleName, const int &uid, std::vector &gids) override { return true; diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/mock_bundle_manager.h b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/mock_bundle_manager.h index 39bfacd9c50..dce7b43aec7 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/mock_bundle_manager.h +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/bundlemgr/mock_bundle_manager.h @@ -143,7 +143,8 @@ public: const std::string &bundleName, const BundleFlag flag, BundleInfo &bundleInfo, int32_t userId) override; virtual bool NotifyAbilityLifeStatus( - const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) override; + const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) + override; virtual bool CheckIsSystemAppByUid(const int uid) override; MOCK_METHOD3(GetApplicationInfos, bool(const ApplicationFlag flag, const int userId, std::vector &appInfos)); @@ -227,7 +228,8 @@ public: bool CheckWantEntity(const AAFwk::Want &, AbilityInfo &); virtual bool NotifyAbilityLifeStatus( - const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) override; + const std::string &bundleName, const std::string &abilityName, const int64_t launchTime, const int uid) + override; MOCK_METHOD2(QueryWantAbility, int(const AAFwk::Want &want, std::vector &abilityInfos)); MOCK_METHOD3(GetApplicationInfos, bool(const ApplicationFlag flag, const int userId, std::vector &appInfos)); -- Gitee From a69452daa4471054b2ac813790190110404bcd7c Mon Sep 17 00:00:00 2001 From: mingxihua Date: Tue, 11 Jan 2022 14:13:34 +0000 Subject: [PATCH 03/11] service leak detection Signed-off-by: detail-hua Signed-off-by: mingxihua --- .../include/ability_connection.h | 17 +++++ .../ability_runtime/include/ability_context.h | 27 ++++---- .../src/ability_connection.cpp | 41 ++++++++++- .../src/connection_manager.cpp | 68 ++++++++++++------- .../native/include/service_extension.h | 6 -- .../kits/ability/native/src/ability.cpp | 5 -- .../native/src/ability_runtime/js_ability.cpp | 4 ++ .../native/src/js_service_extension.cpp | 4 ++ .../ability/native/src/service_extension.cpp | 9 --- .../abilitymgr/include/connection_record.h | 2 +- .../src/ability_connect_manager.cpp | 4 +- services/abilitymgr/src/connection_record.cpp | 6 +- .../connection_record_test.cpp | 2 +- 13 files changed, 128 insertions(+), 67 deletions(-) mode change 100644 => 100755 frameworks/kits/ability/ability_runtime/include/ability_connection.h mode change 100644 => 100755 frameworks/kits/ability/ability_runtime/include/ability_context.h mode change 100644 => 100755 frameworks/kits/ability/ability_runtime/src/ability_connection.cpp mode change 100644 => 100755 frameworks/kits/ability/ability_runtime/src/connection_manager.cpp mode change 100644 => 100755 frameworks/kits/ability/native/include/service_extension.h mode change 100644 => 100755 frameworks/kits/ability/native/src/ability.cpp mode change 100644 => 100755 frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp mode change 100644 => 100755 frameworks/kits/ability/native/src/js_service_extension.cpp mode change 100644 => 100755 frameworks/kits/ability/native/src/service_extension.cpp mode change 100644 => 100755 services/abilitymgr/include/connection_record.h mode change 100644 => 100755 services/abilitymgr/src/ability_connect_manager.cpp mode change 100644 => 100755 services/abilitymgr/src/connection_record.cpp mode change 100644 => 100755 services/abilitymgr/test/unittest/phone/connection_record_test/connection_record_test.cpp diff --git a/frameworks/kits/ability/ability_runtime/include/ability_connection.h b/frameworks/kits/ability/ability_runtime/include/ability_connection.h old mode 100644 new mode 100755 index 13ec528008e..a816e014ad8 --- a/frameworks/kits/ability/ability_runtime/include/ability_connection.h +++ b/frameworks/kits/ability/ability_runtime/include/ability_connection.h @@ -62,8 +62,25 @@ public: * @param resultCode, ERR_OK on success, others on failure. */ void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; + + /** + * set abilityConnectCallback + * + * @param abilityConnectCallback is used to notify caller ability that connect or disconnect is complete + */ + void SetConnectCallback(std::shared_ptr abilityConnectCallback); + + void SetRemoteObject(const sptr &remoteObject); + + void SetResultCode(int resultCode); + + sptr GetRemoteObject(); + + int GetResultCode(); private: std::shared_ptr abilityConnectCallback_; + sptr remoteObject_; + int resultCode_; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/kits/ability/ability_runtime/include/ability_context.h b/frameworks/kits/ability/ability_runtime/include/ability_context.h old mode 100644 new mode 100755 index 9f0563d58bd..10c6e2dae63 --- a/frameworks/kits/ability/ability_runtime/include/ability_context.h +++ b/frameworks/kits/ability/ability_runtime/include/ability_context.h @@ -71,23 +71,24 @@ public: virtual void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData) = 0; /** - * @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template. - * - * @param want Indicates the want containing information about the ability to connect - * @param conn Indicates the callback object when the target ability is connected. - * @return True means success and false means failure - */ + * @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template. + * + * @param want Indicates the want containing information about the ability to connect + * @param connectCallback Indicates the callback object when the target ability is connected. + * @return True means success and false means failure + */ virtual bool ConnectAbility(const AAFwk::Want &want, - const std::shared_ptr &connectCallback) = 0; + const std::shared_ptr &connectCallback) = 0; /** - * @brief Disconnects the current ability from an ability - * - * @param conn Indicates the IAbilityConnection callback object passed by connectAbility after the connection - * is set up. The IAbilityConnection object uniquely identifies a connection between two abilities. - */ + * @brief Disconnects the current ability from an ability + * + * @param want Indicates the want containing information about the ability to disconnect + * @param connectCallback Indicates the callback object when the target ability is connected. + * is set up. The IAbilityConnection object uniquely identifies a connection between two abilities. + */ virtual void DisconnectAbility(const AAFwk::Want &want, - const std::shared_ptr &connectCallback) = 0; + const std::shared_ptr &connectCallback) = 0; /** * @brief get ability info of the current ability diff --git a/frameworks/kits/ability/ability_runtime/src/ability_connection.cpp b/frameworks/kits/ability/ability_runtime/src/ability_connection.cpp old mode 100644 new mode 100755 index b5ebc37be25..eceed62a444 --- a/frameworks/kits/ability/ability_runtime/src/ability_connection.cpp +++ b/frameworks/kits/ability/ability_runtime/src/ability_connection.cpp @@ -19,6 +19,7 @@ namespace OHOS { namespace AbilityRuntime { +const int DIED = -1; AbilityConnection::AbilityConnection(const std::shared_ptr &abilityConnectCallback) { abilityConnectCallback_ = abilityConnectCallback; @@ -31,6 +32,8 @@ void AbilityConnection::OnAbilityConnectDone( if (abilityConnectCallback_ == nullptr) { HILOG_ERROR("%{public}s abilityConnectCallback is nullptr.", __func__); } + SetRemoteObject(remoteObject); + SetResultCode(resultCode); abilityConnectCallback_->OnAbilityConnectDone(element, remoteObject, resultCode); HILOG_DEBUG("%{public}s end, remoteObject:%{public}p, bundleName:%{public}s, abilityName:%{public}s.", __func__, remoteObject.GetRefPtr(), element.GetBundleName().c_str(), element.GetAbilityName().c_str()); @@ -38,13 +41,47 @@ void AbilityConnection::OnAbilityConnectDone( void AbilityConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) { - HILOG_DEBUG("%{public}s begin.", __func__); + HILOG_DEBUG("%{public}s begin, resultCode:%{public}d.", __func__, resultCode); if (abilityConnectCallback_ == nullptr) { HILOG_ERROR("%{public}s abilityConnectCallback is nullptr.", __func__); } - abilityConnectCallback_->OnAbilityDisconnectDone(element, resultCode); + // if resultCode < 0 that means the connectReceiver is died + if (resultCode == DIED) { + bool ret = ConnectionManager::GetInstance().DisconnectReceiver(element); + if (ret) { + HILOG_INFO("The service connection is not disconnected."); + } + abilityConnectCallback_->OnAbilityDisconnectDone(element, DIED + 1); + } else { + abilityConnectCallback_->OnAbilityDisconnectDone(element, resultCode); + } HILOG_DEBUG("%{public}s end, bundleName:%{public}s, abilityName:%{public}s.", __func__, element.GetBundleName().c_str(), element.GetAbilityName().c_str()); } + +void AbilityConnection::SetConnectCallback(std::shared_ptr abilityConnectCallback) +{ + abilityConnectCallback_ = abilityConnectCallback; +} + +void AbilityConnection::SetRemoteObject(const sptr &remoteObject) +{ + remoteObject_ = remoteObject; +} + +void AbilityConnection::SetResultCode(int resultCode) +{ + resultCode_ = resultCode; +} + +sptr AbilityConnection::GetRemoteObject() +{ + return remoteObject_; +} + +int AbilityConnection::GetResultCode() +{ + return resultCode_; +} } // namespace AbilityRuntime } // namespace OHOS \ No newline at end of file diff --git a/frameworks/kits/ability/ability_runtime/src/connection_manager.cpp b/frameworks/kits/ability/ability_runtime/src/connection_manager.cpp old mode 100644 new mode 100755 index e380e4ce517..34024efb2ee --- a/frameworks/kits/ability/ability_runtime/src/connection_manager.cpp +++ b/frameworks/kits/ability/ability_runtime/src/connection_manager.cpp @@ -51,21 +51,32 @@ ErrCode ConnectionManager::ConnectAbility(const sptr &connectCall if (item != abilityConnections_.end()) { std::vector> callbacks = item->second; callbacks.push_back(connectCallback); + abilityConnections_[item->first] = callbacks; abilityConnection = item->first.abilityConnection; - HILOG_INFO("%{public}s find abilityConnection:%{public}p exist, callbackSize:%{public}d.", - __func__, abilityConnection.GetRefPtr(), (int32_t)callbacks.size()); + abilityConnection->SetConnectCallback(connectCallback); + HILOG_INFO("%{public}s end, find abilityConnection:%{public}p exist, callbackSize:%{public}d.", + __func__, abilityConnection.GetRefPtr(), callbacks.size()); + if (abilityConnection->GetResultCode() == ERR_OK) { + connectCallback->OnAbilityConnectDone(connectReceiver, abilityConnection->GetRemoteObject(), + abilityConnection->GetResultCode()); + return ERR_OK; + } else { + return AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, abilityConnection, connectCaller); + } } else { abilityConnection = new AbilityConnection(connectCallback); - ConnectionInfo connectionInfo(connectCaller, connectReceiver, abilityConnection); - std::vector> callbacks; - callbacks.push_back(connectCallback); - abilityConnections_[connectionInfo] = callbacks; - HILOG_DEBUG("%{public}s end, abilityConnection is not exist, make a new abilityConnection.", __func__); - HILOG_DEBUG("%{public}s end, abilityConnection: %{public}p, abilityConnectionsSize:%{public}d.", - __func__, abilityConnection.GetRefPtr(), (int32_t)abilityConnections_.size()); + ErrCode ret = + AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, abilityConnection, connectCaller); + if (ret == ERR_OK) { + ConnectionInfo connectionInfo(connectCaller, connectReceiver, abilityConnection); + std::vector> callbacks; + callbacks.push_back(connectCallback); + abilityConnections_[connectionInfo] = callbacks; + } + HILOG_DEBUG("%{public}s end, not find connection, connection: %{public}p, abilityConnectionsSize:%{public}d.", + __func__, abilityConnection.GetRefPtr(), abilityConnections_.size()); + return ret; } - - return AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, abilityConnection, connectCaller); } ErrCode ConnectionManager::DisconnectAbility(const sptr &connectCaller, @@ -89,20 +100,27 @@ ErrCode ConnectionManager::DisconnectAbility(const sptr &connectC }); if (item != abilityConnections_.end()) { std::vector> callbacks = item->second; - HILOG_DEBUG("%{public}s begin remove callback, callbackSize:%{public}d.", __func__, (int32_t)callbacks.size()); - for (auto iter = callbacks.begin(); iter != callbacks.end(); iter++) { + HILOG_DEBUG("%{public}s begin remove callback, callbackSize:%{public}d.", __func__, callbacks.size()); + auto iter = callbacks.begin(); + while (iter != callbacks.end()) { if (*iter == connectCallback) { - callbacks.erase(iter); + iter = callbacks.erase(iter); + } else { + iter++; } } + abilityConnections_[item->first] = callbacks; sptr abilityConnection; abilityConnection = item->first.abilityConnection; + abilityConnection->SetConnectCallback(connectCallback); HILOG_INFO("%{public}s end, find abilityConnection:%{public}p exist, abilityConnectionsSize:%{public}d.", - __func__, abilityConnection.GetRefPtr(), (int32_t)abilityConnections_.size()); + __func__, abilityConnection.GetRefPtr(), abilityConnections_.size()); if (callbacks.size() == 0) { + abilityConnections_.erase(item); HILOG_DEBUG("%{public}s disconnectAbility.", __func__); return AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(abilityConnection); } else { + connectCallback->OnAbilityDisconnectDone(connectReceiver, ERR_OK); HILOG_DEBUG("%{public}s callbacks is not empty, do not need disconnectAbility.", __func__); return ERR_OK; } @@ -119,13 +137,17 @@ bool ConnectionManager::DisconnectCaller(const sptr &connectCalle HILOG_ERROR("%{public}s end, connectCaller is nullptr.", __func__); return false; } + HILOG_DEBUG("%{public}s, connectCaller:%{public}p, abilityConnectionsSize:%{public}d.", - __func__, connectCaller.GetRefPtr(), (int32_t)abilityConnections_.size()); + __func__, connectCaller.GetRefPtr(), abilityConnections_.size()); + bool isDisconnect = false; auto iter = abilityConnections_.begin(); while (iter != abilityConnections_.end()) { ConnectionInfo connectionInfo = iter->first; if (IsConnectCallerEqual(connectionInfo.connectCaller, connectCaller)) { + HILOG_DEBUG("%{public}s DisconnectAbility connection:%{public}p.", + __func__, connectionInfo.abilityConnection.GetRefPtr()); ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(connectionInfo.abilityConnection); if (ret != ERR_OK) { @@ -138,25 +160,21 @@ bool ConnectionManager::DisconnectCaller(const sptr &connectCalle } } - HILOG_DEBUG("%{public}s end, abilityConnectionsSize:%{public}d.", __func__, (int32_t)abilityConnections_.size()); + HILOG_DEBUG("%{public}s end, abilityConnectionsSize:%{public}d.", __func__, abilityConnections_.size()); return isDisconnect; } bool ConnectionManager::DisconnectReceiver(const AppExecFwk::ElementName &connectReceiver) { HILOG_DEBUG("%{public}s begin, abilityConnectionsSize:%{public}d, bundleName:%{public}s, abilityName:%{public}s.", - __func__, (int32_t)abilityConnections_.size(), connectReceiver.GetBundleName().c_str(), + __func__, abilityConnections_.size(), connectReceiver.GetBundleName().c_str(), connectReceiver.GetAbilityName().c_str()); + bool isDisconnect = false; auto iter = abilityConnections_.begin(); while (iter != abilityConnections_.end()) { ConnectionInfo connectionInfo = iter->first; if (IsConnectReceiverEqual(connectionInfo.connectReceiver, connectReceiver)) { - ErrCode ret = - AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(connectionInfo.abilityConnection); - if (ret != ERR_OK) { - HILOG_ERROR("%{public}s ams->DisconnectAbility error, ret=%{public}d", __func__, ret); - } iter = abilityConnections_.erase(iter); isDisconnect = true; } else { @@ -164,7 +182,7 @@ bool ConnectionManager::DisconnectReceiver(const AppExecFwk::ElementName &connec } } - HILOG_DEBUG("%{public}s end, abilityConnectionsSize:%{public}d.", __func__, (int32_t)abilityConnections_.size()); + HILOG_DEBUG("%{public}s end, abilityConnectionsSize:%{public}d.", __func__, abilityConnections_.size()); return isDisconnect; } @@ -181,4 +199,4 @@ bool ConnectionManager::IsConnectReceiverEqual(const AppExecFwk::ElementName &co connectReceiver.GetAbilityName() == connectReceiverOther.GetAbilityName(); } } // namespace AbilityRuntime -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/kits/ability/native/include/service_extension.h b/frameworks/kits/ability/native/include/service_extension.h old mode 100644 new mode 100755 index 044a00dc630..8153c674659 --- a/frameworks/kits/ability/native/include/service_extension.h +++ b/frameworks/kits/ability/native/include/service_extension.h @@ -66,12 +66,6 @@ public: * @return The ServiceExtension instance. */ static ServiceExtension* Create(const std::unique_ptr& runtime); - - /** - * @brief Stop the extension. - * - */ - virtual void OnStop() override; }; } // namespace AbilityRuntime } // namespace OHOS diff --git a/frameworks/kits/ability/native/src/ability.cpp b/frameworks/kits/ability/native/src/ability.cpp old mode 100644 new mode 100755 index f62297a73c2..d266dca5e9c --- a/frameworks/kits/ability/native/src/ability.cpp +++ b/frameworks/kits/ability/native/src/ability.cpp @@ -267,11 +267,6 @@ void Ability::OnStop() return; } lifecycle_->DispatchLifecycle(LifeCycle::Event::ON_STOP); - - bool ret = AbilityRuntime::ConnectionManager::GetInstance().DisconnectCaller(AbilityContext::token_); - if (ret) { - APP_LOGI("The service connection is not disconnected."); - } APP_LOGI("%{public}s end.", __func__); } diff --git a/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp b/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp old mode 100644 new mode 100755 index 8341a2f764b..d4fdcfcca84 --- a/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp +++ b/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp @@ -116,6 +116,10 @@ void JsAbility::OnStop() Ability::OnStop(); CallObjectMethod("onDestroy"); + bool ret = ConnectionManager::GetInstance().DisconnectCaller(AbilityContext::token_); + if (ret) { + HILOG_INFO("The service connection is not disconnected."); + } } void JsAbility::OnSceneCreated() diff --git a/frameworks/kits/ability/native/src/js_service_extension.cpp b/frameworks/kits/ability/native/src/js_service_extension.cpp old mode 100644 new mode 100755 index 4437c35f9c4..c4294fa2cc0 --- a/frameworks/kits/ability/native/src/js_service_extension.cpp +++ b/frameworks/kits/ability/native/src/js_service_extension.cpp @@ -107,6 +107,10 @@ void JsServiceExtension::OnStop() ServiceExtension::OnStop(); HILOG_INFO("JsServiceExtension OnStop begin."); CallObjectMethod("onDestroy"); + bool ret = ConnectionManager::GetInstance().DisconnectCaller(GetContext()->GetToken()); + if (ret) { + HILOG_INFO("The service extension connection is not disconnected."); + } HILOG_INFO("%{public}s end.", __func__); } diff --git a/frameworks/kits/ability/native/src/service_extension.cpp b/frameworks/kits/ability/native/src/service_extension.cpp old mode 100644 new mode 100755 index f360b81668a..d80007139c1 --- a/frameworks/kits/ability/native/src/service_extension.cpp +++ b/frameworks/kits/ability/native/src/service_extension.cpp @@ -65,14 +65,5 @@ std::shared_ptr ServiceExtension::CreateAndInitContext( context->SetAbilityInfo(record->GetAbilityInfo()); return context; } - -void ServiceExtension::OnStop() -{ - Extension::OnStop(); - bool ret = ConnectionManager::GetInstance().DisconnectCaller(GetContext()->GetToken()); - if (ret) { - HILOG_INFO("The service connection is not disconnected."); - } -} } } \ No newline at end of file diff --git a/services/abilitymgr/include/connection_record.h b/services/abilitymgr/include/connection_record.h old mode 100644 new mode 100755 index 78894354ecc..0dbc77a3eff --- a/services/abilitymgr/include/connection_record.h +++ b/services/abilitymgr/include/connection_record.h @@ -101,7 +101,7 @@ public: * complete disconnect ability and invoke callback. * */ - void CompleteDisconnect(int resultCode); + void CompleteDisconnect(int resultCode, bool isDied); /** * scheduler target service disconnect done. diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp old mode 100644 new mode 100755 index 29356963aa4..7ef5c48e229 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -660,7 +660,7 @@ void AbilityConnectManager::HandleDisconnectTask(const ConnectListType &connectl if (targetService && connectRecord->GetConnectState() == ConnectionState::DISCONNECTED && targetService->GetConnectRecordList().size() > 1) { HILOG_WARN("This record complete disconnect directly. recordId:%{public}d", connectRecord->GetRecordId()); - connectRecord->CompleteDisconnect(ERR_OK); + connectRecord->CompleteDisconnect(ERR_OK, false); targetService->RemoveConnectRecordFromList(connectRecord); RemoveConnectionRecordFromMap(connectRecord); }; @@ -907,7 +907,7 @@ void AbilityConnectManager::HandleAbilityDiedTask(const std::shared_ptrGetConnectRecordList(); for (auto &connectRecord : connlist) { HILOG_WARN("This record complete disconnect directly. recordId:%{public}d", connectRecord->GetRecordId()); - connectRecord->CompleteDisconnect(ERR_OK); + connectRecord->CompleteDisconnect(ERR_OK, true); abilityRecord->RemoveConnectRecordFromList(connectRecord); RemoveConnectionRecordFromMap(connectRecord); } diff --git a/services/abilitymgr/src/connection_record.cpp b/services/abilitymgr/src/connection_record.cpp old mode 100644 new mode 100755 index 2ccef86617b..b0f8c46f66b --- a/services/abilitymgr/src/connection_record.cpp +++ b/services/abilitymgr/src/connection_record.cpp @@ -123,12 +123,12 @@ void ConnectionRecord::CompleteConnect(int resultCode) AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name); auto remoteObject = targetService_->GetConnRemoteObject(); if (connCallback_) { - connCallback_->OnAbilityConnectDone(element, remoteObject, resultCode); + connCallback_->OnAbilityDisconnectDone(element, isDied ? (resultCode - 1) : resultCode); } HILOG_INFO("result: %{public}d. connectstate:%{public}d.", resultCode, state_); } -void ConnectionRecord::CompleteDisconnect(int resultCode) +void ConnectionRecord::CompleteDisconnect(int resultCode, bool isDied) { if (resultCode == ERR_OK) { SetConnectState(ConnectionState::DISCONNECTED); @@ -157,7 +157,7 @@ void ConnectionRecord::ScheduleDisconnectAbilityDone() handler->RemoveTask(taskName); } - CompleteDisconnect(ERR_OK); + CompleteDisconnect(ERR_OK, false); } void ConnectionRecord::ScheduleConnectAbilityDone() diff --git a/services/abilitymgr/test/unittest/phone/connection_record_test/connection_record_test.cpp b/services/abilitymgr/test/unittest/phone/connection_record_test/connection_record_test.cpp old mode 100644 new mode 100755 index f9dbb791c34..8b0f157a10c --- a/services/abilitymgr/test/unittest/phone/connection_record_test/connection_record_test.cpp +++ b/services/abilitymgr/test/unittest/phone/connection_record_test/connection_record_test.cpp @@ -213,7 +213,7 @@ HWTEST_F(ConnectionRecordTest, AaFwk_ConnectionRecord_007, TestSize.Level1) { EXPECT_CALL(*callback_, OnAbilityDisconnectDone(::testing::_, ::testing::_)).Times(1); - connectionRecord_->CompleteDisconnect(ERR_OK); + connectionRecord_->CompleteDisconnect(ERR_OK, false); EXPECT_EQ(connectionRecord_->GetConnectState(), ConnectionState::DISCONNECTED); } -- Gitee From a3cc37fe646e52da29f6138a8fae66cedd7adbff Mon Sep 17 00:00:00 2001 From: mingxihua Date: Tue, 11 Jan 2022 14:36:55 +0000 Subject: [PATCH 04/11] service leak detection Signed-off-by: detail-hua Signed-off-by: mingxihua --- services/abilitymgr/src/connection_record.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/abilitymgr/src/connection_record.cpp b/services/abilitymgr/src/connection_record.cpp index b0f8c46f66b..56e8efe29a0 100755 --- a/services/abilitymgr/src/connection_record.cpp +++ b/services/abilitymgr/src/connection_record.cpp @@ -123,7 +123,7 @@ void ConnectionRecord::CompleteConnect(int resultCode) AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name); auto remoteObject = targetService_->GetConnRemoteObject(); if (connCallback_) { - connCallback_->OnAbilityDisconnectDone(element, isDied ? (resultCode - 1) : resultCode); + connCallback_->OnAbilityConnectDone(element, remoteObject, resultCode); } HILOG_INFO("result: %{public}d. connectstate:%{public}d.", resultCode, state_); } @@ -137,7 +137,7 @@ void ConnectionRecord::CompleteDisconnect(int resultCode, bool isDied) const AppExecFwk::AbilityInfo &abilityInfo = targetService_->GetAbilityInfo(); AppExecFwk::ElementName element(abilityInfo.deviceId, abilityInfo.bundleName, abilityInfo.name); if (connCallback_) { - connCallback_->OnAbilityDisconnectDone(element, resultCode); + connCallback_->OnAbilityDisconnectDone(element, isDied ? (resultCode - 1) : resultCode); } HILOG_INFO("result: %{public}d. connectstate:%{public}d.", resultCode, state_); } -- Gitee From 292b8f9ab0ca6e312cd55b04664df8c6cca0b6b6 Mon Sep 17 00:00:00 2001 From: mingxihua Date: Tue, 11 Jan 2022 14:40:26 +0000 Subject: [PATCH 05/11] service leak detection Signed-off-by: detail-hua Signed-off-by: mingxihua --- .../kits/ability/native/src/ability_runtime/js_ability.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp b/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp index d4fdcfcca84..e087171f79f 100755 --- a/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp +++ b/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp @@ -18,6 +18,7 @@ #include "ability_runtime/js_ability_context.h" #include "ability_runtime/js_window_stage.h" #include "ability_start_setting.h" +#include "connection_manager.h" #include "hilog_wrapper.h" #include "js_data_struct_converter.h" #include "js_runtime.h" -- Gitee From cbb3bfc26ebfdb7531f839c6a30d285e4d10cabf Mon Sep 17 00:00:00 2001 From: laoyitong Date: Tue, 11 Jan 2022 23:33:46 +0800 Subject: [PATCH 06/11] laoyitong@huawei.com Signed-off-by: laoyitong Change-Id: If4129e8cc3fdb18dca6081cca19e8afd35dd58cd --- .../include/mock_ability_manager_service.h | 8 +++ .../mock/AMS/mock_ability_manager_service.h | 8 +++ .../AMS/mock_serviceability_manager_service.h | 8 +++ .../include/ability_manager_client.h | 17 +++++ .../include/ability_manager_interface.h | 11 +++ .../include/mission_snapshot.h | 6 +- .../ability_manager/include/snapshot.h | 68 +++++++++++++++++++ .../kits/napi/aafwk/mission_manager/BUILD.gn | 1 + .../aafwk/mission_manager/mission_manager.cpp | 38 ++++++++++- .../include/ability_manager_proxy.h | 4 ++ .../include/ability_manager_service.h | 6 ++ .../abilitymgr/include/ability_manager_stub.h | 2 + .../abilitymgr/src/ability_manager_client.cpp | 15 ++++ .../abilitymgr/src/ability_manager_proxy.cpp | 52 ++++++++++++++ .../src/ability_manager_service.cpp | 19 ++++++ .../abilitymgr/src/ability_manager_stub.cpp | 27 ++++++++ services/abilitymgr/src/mission_snapshot.cpp | 40 +++++++++++ .../ability_manager_stub_mock.h | 8 +++ .../ability_manager_stub_impl_mock.h | 8 +++ .../ability_manager_stub_mock.h | 8 +++ .../mock/include/mock_ability_mgr_service.h | 8 +++ tools/test/mock/mock_ability_manager_stub.h | 8 +++ 22 files changed, 368 insertions(+), 2 deletions(-) create mode 100644 interfaces/innerkits/ability_manager/include/snapshot.h diff --git a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h index 572bf7c4d0f..fd36397f624 100755 --- a/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_ability_manager_service.h @@ -219,6 +219,14 @@ public: { return 0; } + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) + { + return 0; + } + virtual int RegisterSnapshotHandler(const sptr& handler) + { + return 0; + } enum RequestCode { E_STATE_INITIAL = 0, diff --git a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h index 2c172379b52..6e2af77dfd3 100644 --- a/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_ability_manager_service.h @@ -186,6 +186,14 @@ public: { return 0; } + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) + { + return 0; + } + virtual int RegisterSnapshotHandler(const sptr& handler) + { + return 0; + } AbilityLifeCycleState curstate_ = AbilityLifeCycleState::ABILITY_STATE_INITIAL; sptr abilityScheduler_; // kit interface used to schedule ability life diff --git a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h index c27d94e0e0c..90a6d7f0fbd 100755 --- a/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h +++ b/frameworks/kits/test/mock/AMS/mock_serviceability_manager_service.h @@ -202,6 +202,14 @@ public: { return 0; } + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) + { + return 0; + } + virtual int RegisterSnapshotHandler(const sptr& handler) + { + return 0; + } sptr abilityScheduler_ = nullptr; // kit interface used to schedule ability life Want want_; diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_client.h b/interfaces/innerkits/ability_manager/include/ability_manager_client.h index 57887f13dc8..f4271493446 100644 --- a/interfaces/innerkits/ability_manager/include/ability_manager_client.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_client.h @@ -22,6 +22,7 @@ #include "ability_manager_errors.h" #include "ability_scheduler_interface.h" #include "ability_manager_interface.h" +#include "snapshot.h" #include "want.h" #include "iremote_object.h" @@ -568,6 +569,15 @@ public: */ ErrCode GetMissionInfo(const std::string& deviceId, int32_t missionId, MissionInfo &missionInfo); + /** + * @brief Get the Mission Snapshot Info object + * @param deviceId local or remote deviceid. + * @param missionId Id of target mission. + * @param snapshot snapshot of target mission + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot); + /** * @brief Clean mission by id. * @param missionId Id of target mission. @@ -623,6 +633,13 @@ public: * @return Returns ERR_OK on success, others on failure. */ ErrCode StopUser(int accountId, const sptr &callback); + + /** + * @brief Register the snapshot handler + * @param handler snapshot handler + * @return ErrCode Returns ERR_OK on success, others on failure. + */ + ErrCode RegisterSnapshotHandler(const sptr& handler); private: static std::mutex mutex_; static std::shared_ptr instance_; diff --git a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h index 31bf7e3d1cd..4357ee24a3c 100755 --- a/interfaces/innerkits/ability_manager/include/ability_manager_interface.h +++ b/interfaces/innerkits/ability_manager/include/ability_manager_interface.h @@ -40,6 +40,7 @@ #include "system_memory_attr.h" #include "mission_listener_interface.h" #include "mission_info.h" +#include "snapshot.h" #include "start_options.h" #include "stop_user_callback.h" #include "remote_mission_listener_interface.h" @@ -531,6 +532,8 @@ public: virtual int GetMissionInfo(const std::string& deviceId, int32_t missionId, MissionInfo &missionInfo) = 0; + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) = 0; + virtual int CleanMission(int32_t missionId) = 0; virtual int CleanAllMissions() = 0; @@ -563,6 +566,13 @@ public: virtual int UnRegisterMissionListener(const std::string &deviceId, const sptr &listener) = 0; + /** + * @brief Register the snapshot handler + * @param handler snapshot handler + * @return int Returns ERR_OK on success, others on failure. + */ + virtual int RegisterSnapshotHandler(const sptr& handler) = 0; + enum { // ipc id 1-1000 for kit // ipc id for terminating ability (1) @@ -783,6 +793,7 @@ public: UNREGISTER_REMOTE_MISSION_LISTENER = 1111, START_SYNC_MISSIONS = 1112, STOP_SYNC_MISSIONS = 1113, + REGISTER_SNAPSHOT_HANDLER = 1114, // ipc id 2001-3000 for tools // ipc id for dumping state (2001) diff --git a/interfaces/innerkits/ability_manager/include/mission_snapshot.h b/interfaces/innerkits/ability_manager/include/mission_snapshot.h index ed1b0dd209a..ca1fdcbdf7a 100644 --- a/interfaces/innerkits/ability_manager/include/mission_snapshot.h +++ b/interfaces/innerkits/ability_manager/include/mission_snapshot.h @@ -37,9 +37,13 @@ struct MissionPixelMap : public Parcelable { static MissionPixelMap *Unmarshalling(Parcel &parcel); }; -struct MissionSnapshot { +struct MissionSnapshot : public Parcelable { AppExecFwk::ElementName topAbility; std::shared_ptr snapshot; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static MissionSnapshot *Unmarshalling(Parcel &parcel); }; } // namespace AAFwk diff --git a/interfaces/innerkits/ability_manager/include/snapshot.h b/interfaces/innerkits/ability_manager/include/snapshot.h new file mode 100644 index 00000000000..9236a4e8cb2 --- /dev/null +++ b/interfaces/innerkits/ability_manager/include/snapshot.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2021 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_AAFWK_SNAPSHOT_H +#define OHOS_AAFWK_SNAPSHOT_H + +#include + +namespace OHOS { +namespace Media { +class PixelMap; +} +namespace AAFwk { +/** + * @class Snapshot + * Snapshot info + */ +class Snapshot { +public: + Snapshot() = default; + ~Snapshot() = default; + const std::shared_ptr& GetPixelMap() const + { + return pixelMap_; + } + void SetPixelMap(const std::shared_ptr& pixelMap) + { + pixelMap_ = pixelMap; + } +private: + std::shared_ptr pixelMap_ = nullptr; +}; + +/** + * @class ISnapshotHandler + * Snapshot handler, use to get snapshot + */ +class ISnapshotHandler : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.SnapshotHandler"); + + enum { + TRANS_ID_GET_SNAPSHOT + }; + + /** + * @brief Get the Snapshot object + * @param token remote object token + * @param snapshot the application snapshot + * @return int32_t function result + */ + virtual int32_t GetSnapshot(const sptr& token, Snapshot& snapshot) = 0; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_SNAPSHOT_H \ No newline at end of file diff --git a/interfaces/kits/napi/aafwk/mission_manager/BUILD.gn b/interfaces/kits/napi/aafwk/mission_manager/BUILD.gn index 000028cc9b2..f0acd3349d4 100644 --- a/interfaces/kits/napi/aafwk/mission_manager/BUILD.gn +++ b/interfaces/kits/napi/aafwk/mission_manager/BUILD.gn @@ -46,6 +46,7 @@ ohos_shared_library("missionmanager_napi") { "appexecfwk_standard:appexecfwk_base", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", + "multimedia_image_standard:image", ] relative_install_dir = "module/application" diff --git a/interfaces/kits/napi/aafwk/mission_manager/mission_manager.cpp b/interfaces/kits/napi/aafwk/mission_manager/mission_manager.cpp index 1deb73c862f..3f9a59de06d 100644 --- a/interfaces/kits/napi/aafwk/mission_manager/mission_manager.cpp +++ b/interfaces/kits/napi/aafwk/mission_manager/mission_manager.cpp @@ -23,6 +23,7 @@ #include "js_mission_listener.h" #include "js_runtime_utils.h" #include "mission_snapshot.h" +#include "pixel_map_napi.h" #include @@ -30,6 +31,10 @@ namespace OHOS { namespace AbilityRuntime { using namespace OHOS::AppExecFwk; using AbilityManagerClient = AAFwk::AbilityManagerClient; +namespace { + constexpr int32_t ARG_COUNT_TWO = 1; + constexpr int32_t ARG_COUNT_THREE = 1; +} class JsMissionManager { public: JsMissionManager() = default; @@ -241,7 +246,38 @@ private: NativeValue* OnGetMissionSnapShot(NativeEngine &engine, NativeCallbackInfo &info) { HILOG_INFO("%{public}s is called", __FUNCTION__); - return nullptr; + if (info.argc != ARG_COUNT_TWO && info.argc != ARG_COUNT_THREE) { + HILOG_ERROR("missionSnapshot: need two or three params"); + return engine.CreateUndefined(); + } + std::string deviceId; + if (!ConvertFromJsValue(engine, info.argv[0], deviceId)) { + HILOG_ERROR("missionSnapshot: Parse deviceId failed"); + return engine.CreateUndefined(); + } + int32_t missionId = -1; + if (!ConvertFromJsValue(engine, info.argv[0], missionId)) { + HILOG_ERROR("missionSnapshot: Parse missionId failed"); + return engine.CreateUndefined(); + } + AsyncTask::CompleteCallback complete = + [deviceId, missionId](NativeEngine &engine, AsyncTask &task, int32_t status) { + AAFwk::MissionSnapshot missionSnapshot; + auto errcode = AbilityManagerClient::GetInstance()->GetMissionSnapshot( + deviceId, missionId, missionSnapshot); + if (errcode == 0) { + auto nativeValue = reinterpret_cast(Media::PixelMapNapi::CreatePixelMap( + reinterpret_cast(&engine), missionSnapshot.snapshot)); + task.Resolve(engine, nativeValue); + } else { + task.Reject(engine, CreateJsError(engine, errcode, "Get mission snapshot failed.")); + } + }; + NativeValue* lastParam = (info.argc == ARG_COUNT_TWO) ? nullptr : info.argv[2]; + NativeValue* result = nullptr; + AsyncTask::Schedule( + engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result)); + return result; } NativeValue* OnLockMission(NativeEngine &engine, NativeCallbackInfo &info) diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index 849cd60fd05..ed35e559fbf 100755 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -531,6 +531,10 @@ public: virtual int UnRegisterMissionListener(const std::string &deviceId, const sptr &listener) override; + virtual int RegisterSnapshotHandler(const sptr& handler) override; + + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) override; + private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 04fd7a110a0..bf5bee2b625 100755 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -707,6 +707,11 @@ public: virtual int StopUser(int userId, const sptr &callback) override; + virtual int RegisterSnapshotHandler(const sptr& handler) override; + + virtual int32_t GetMissionSnapshot(const std::string& deviceId, int32_t missionId, + MissionSnapshot& snapshot) override; + // MSG 0 - 20 represents timeout message static constexpr uint32_t LOAD_TIMEOUT_MSG = 0; static constexpr uint32_t ACTIVE_TIMEOUT_MSG = 1; @@ -890,6 +895,7 @@ private: std::unordered_map> missionListManagers_; std::shared_ptr currentMissionListManager_; std::shared_ptr kernalAbilityManager_; + sptr snapshotHandler_; }; } // namespace AAFwk diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 3609c0e65b2..21aa80c8c3d 100755 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -128,6 +128,8 @@ private: int StartSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply); int StopSyncRemoteMissionsInner(MessageParcel &data, MessageParcel &reply); + int RegisterSnapshotHandlerInner(MessageParcel &data, MessageParcel &reply); + int GetMissionSnapshotInfoInner(MessageParcel &data, MessageParcel &reply); using RequestFuncType = int (AbilityManagerStub::*)(MessageParcel &data, MessageParcel &reply); std::map requestFuncMap_; diff --git a/services/abilitymgr/src/ability_manager_client.cpp b/services/abilitymgr/src/ability_manager_client.cpp index 8c336f67077..c54f280f0db 100644 --- a/services/abilitymgr/src/ability_manager_client.cpp +++ b/services/abilitymgr/src/ability_manager_client.cpp @@ -794,5 +794,20 @@ ErrCode AbilityManagerClient::StopUser(int accountId, const sptr abms = iface_cast(remoteObject_); return abms->StopUser(accountId, callback); } + +ErrCode AbilityManagerClient::RegisterSnapshotHandler(const sptr& handler) +{ + CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); + auto abms = iface_cast(remoteObject_); + return abms->RegisterSnapshotHandler(handler); +} + +ErrCode AbilityManagerClient::GetMissionSnapshot(const std::string& deviceId, int32_t missionId, + MissionSnapshot& snapshot) +{ + CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, ABILITY_SERVICE_NOT_CONNECTED); + auto abms = iface_cast(remoteObject_); + return abms->GetMissionSnapshot(deviceId, missionId, snapshot); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 0d8de5e105b..559c1dcbf61 100755 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -666,6 +666,38 @@ int AbilityManagerProxy::GetMissionSnapshot(const int32_t missionId, MissionPixe return reply.ReadInt32(); } +int AbilityManagerProxy::GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) +{ + int error; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (!data.WriteString(deviceId)) { + HILOG_ERROR("deviceId write failed."); + return INNER_ERR; + } + if (!data.WriteInt32(missionId)) { + HILOG_ERROR("missionId write failed."); + return ERR_INVALID_VALUE; + } + error = Remote()->SendRequest(IAbilityManager::GET_MISSION_SNAPSHOT, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return error; + } + std::unique_ptr info(reply.ReadParcelable()); + if (!info) { + HILOG_ERROR("readParcelableInfo failed."); + return ERR_UNKNOWN_OBJECT; + } + snapshot = *info; + return reply.ReadInt32(); +} + int AbilityManagerProxy::MoveMissionToTop(int32_t missionId) { int error; @@ -2033,5 +2065,25 @@ int AbilityManagerProxy::UnRegisterMissionListener(const std::string &deviceId, } return reply.ReadInt32(); } + +int AbilityManagerProxy::RegisterSnapshotHandler(const sptr& handler) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (!data.WriteRemoteObject(handler->AsObject())) { + HILOG_ERROR("snapshot: handler write failed."); + return INNER_ERR; + } + auto error = Remote()->SendRequest(IAbilityManager::REGISTER_SNAPSHOT_HANDLER, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("snapshot: send request error: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 3fc23ab7ce5..016320bfe55 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -2776,5 +2776,24 @@ int AbilityManagerService::StopUser(int userId, const sptr &c } return 0; } + +int AbilityManagerService::RegisterSnapshotHandler(const sptr& handler) +{ + HILOG_INFO("snapshot: AbilityManagerService register snapshot handler success."); + snapshotHandler_ = handler; + return 0; +} + +int32_t AbilityManagerService::GetMissionSnapshot(const std::string& deviceId, int32_t missionId, + MissionSnapshot& missionSnapshot) +{ + if (!snapshotHandler_) { + return 0; + } + Snapshot snapshot; + int32_t result = snapshotHandler_->GetSnapshot(GetAbilityTokenByMissionId(missionId), snapshot); + missionSnapshot.snapshot = snapshot.GetPixelMap(); + return result; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 8f0ec348e00..bfb6d7b5cd4 100755 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -1179,5 +1179,32 @@ int AbilityManagerStub::UnRegisterRemoteMissionListenerInner(MessageParcel &data HILOG_INFO("AbilityManagerStub: UnRegisterRemoteMissionListenerInner result = %{public}d", result); return result; } + +int AbilityManagerStub::RegisterSnapshotHandlerInner(MessageParcel &data, MessageParcel &reply) +{ + sptr handler = iface_cast(data.ReadRemoteObject()); + if (handler == nullptr) { + HILOG_ERROR("snapshot: AbilityManagerStub read snapshot handler failed!"); + return ERR_NULL_OBJECT; + } + int32_t result = RegisterSnapshotHandler(handler); + HILOG_INFO("snapshot: AbilityManagerStub register snapshot handler result = %{public}d", result); + return result; +} + +int AbilityManagerStub::GetMissionSnapshotInfoInner(MessageParcel &data, MessageParcel &reply) +{ + std::string deviceId = data.ReadString(); + if (deviceId.empty()) { + HILOG_ERROR("missionSnapshot: get deviceId empty!"); + return ERR_NULL_OBJECT; + } + int32_t missionId = data.ReadInt32(); + MissionSnapshot missionSnapshot; + int32_t result = GetMissionSnapshot(deviceId, missionId, missionSnapshot); + HILOG_INFO("snapshot: AbilityManagerStub get snapshot result = %{public}d", result); + reply.WriteParcelable(&missionSnapshot); + return result; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/mission_snapshot.cpp b/services/abilitymgr/src/mission_snapshot.cpp index 1cb4cc91885..05caf6b6fa1 100644 --- a/services/abilitymgr/src/mission_snapshot.cpp +++ b/services/abilitymgr/src/mission_snapshot.cpp @@ -60,5 +60,45 @@ bool MissionPixelMap::Marshalling(Parcel &parcel) const } return true; } + +bool MissionSnapshot::ReadFromParcel(Parcel &parcel) +{ + std::unique_ptr ability(parcel.ReadParcelable()); + if (ability == nullptr) { + return false; + } + topAbility = *ability; + std::shared_ptr pixelMap(parcel.ReadParcelable()); + if (ability == nullptr) { + return false; + } + snapshot = pixelMap; + return true; +} + +MissionSnapshot *MissionSnapshot::Unmarshalling(Parcel &parcel) +{ + MissionSnapshot *info = new (std::nothrow) MissionSnapshot(); + if (info == nullptr) { + return nullptr; + } + + if (!info->ReadFromParcel(parcel)) { + delete info; + info = nullptr; + } + return info; +} + +bool MissionSnapshot::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteParcelable(&topAbility)) { + return false; + } + if (!parcel.WriteParcelable(snapshot.get())) { + return false; + } + return true; +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h index 5f1bfccf169..3f452557446 100755 --- a/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_proxy_test/ability_manager_stub_mock.h @@ -326,6 +326,14 @@ public: { return 0; } + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) + { + return 0; + } + virtual int RegisterSnapshotHandler(const sptr& handler) + { + return 0; + } MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr &callerToken, int requestCode)); MOCK_METHOD3(StartAbility, int(const Want &want, const sptr &callerToken, int requestCode)); MOCK_METHOD2( diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h index 5e8cc329447..77f2a6c4c09 100755 --- a/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_stub_test/ability_manager_stub_impl_mock.h @@ -368,6 +368,14 @@ public: { return 0; } + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) + { + return 0; + } + virtual int RegisterSnapshotHandler(const sptr& handler) + { + return 0; + } }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h index d7240704c88..f576842ebce 100755 --- a/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h +++ b/services/abilitymgr/test/unittest/phone/ability_manager_test/ability_manager_stub_mock.h @@ -130,6 +130,14 @@ public: { return 0; } + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) + { + return 0; + } + virtual int RegisterSnapshotHandler(const sptr& handler) + { + return 0; + } }; } // namespace AAFwk } // namespace OHOS diff --git a/services/test/mock/include/mock_ability_mgr_service.h b/services/test/mock/include/mock_ability_mgr_service.h index 168aad5e16d..cad93a239f6 100755 --- a/services/test/mock/include/mock_ability_mgr_service.h +++ b/services/test/mock/include/mock_ability_mgr_service.h @@ -136,6 +136,14 @@ public: { return 0; } + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) + { + return 0; + } + virtual int RegisterSnapshotHandler(const sptr& handler) + { + return 0; + } void Wait() { diff --git a/tools/test/mock/mock_ability_manager_stub.h b/tools/test/mock/mock_ability_manager_stub.h index 27beedce574..0f0dd565e6a 100755 --- a/tools/test/mock/mock_ability_manager_stub.h +++ b/tools/test/mock/mock_ability_manager_stub.h @@ -161,6 +161,14 @@ public: { return 0; } + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& snapshot) + { + return 0; + } + virtual int RegisterSnapshotHandler(const sptr& handler) + { + return 0; + } public: std::string powerState_; }; -- Gitee From 6e03042f62de317054003e2e06fff6c5e103001c Mon Sep 17 00:00:00 2001 From: xuchenghua Date: Wed, 12 Jan 2022 09:26:22 +0000 Subject: [PATCH 07/11] xuchenghua09@huawei.com Signed-off-by: xuchenghua --- services/abilitymgr/BUILD.gn | 5 + services/abilitymgr/abilitymgr.gni | 4 + .../include/ability_manager_service.h | 22 +- services/abilitymgr/include/ability_record.h | 4 + services/abilitymgr/include/app_scheduler.h | 5 +- services/abilitymgr/include/user_controller.h | 126 +++++ .../abilitymgr/include/user_event_handler.h | 52 ++ .../src/ability_connect_manager.cpp | 2 +- .../src/ability_manager_service.cpp | 158 +++++-- services/abilitymgr/src/ability_record.cpp | 13 +- services/abilitymgr/src/app_scheduler.cpp | 11 +- services/abilitymgr/src/user_controller.cpp | 445 ++++++++++++++++++ .../abilitymgr/src/user_event_handler.cpp | 42 ++ services/abilitymgr/test/BUILD.gn | 7 + .../mock/include/mock_app_manager_client.h | 4 +- .../test/mock/include/mock_app_mgr_client.h | 2 +- .../include/appmgr/app_mgr_client.h | 2 +- .../src/appmgr/app_mgr_client.cpp | 2 +- .../src/appmgr/mock_app_scheduler.cpp | 3 +- .../ability_dump_test/ability_dump_test.cpp | 4 +- .../ability_manager_service_test.cpp | 4 +- .../ability_stack_manager_test.cpp | 2 +- .../ability_with_applications_test.cpp | 4 +- .../abilityms_appms_test.cpp | 4 +- .../app_scheduler_test/app_scheduler_test.cpp | 6 +- .../phone/lifecycle_test/lifecycle_test.cpp | 4 +- .../terminate_ability_test.cpp | 4 +- .../test/mock/include/mock_app_mgr_client.h | 4 +- .../ability_mgr_module_test.cpp | 61 +-- .../ability_record_module_test.cpp | 7 +- .../ability_stack_module_test.cpp | 2 +- .../dump_module_test/dump_module_test.cpp | 2 +- .../panding_want_manager_test.cpp | 8 +- 33 files changed, 928 insertions(+), 97 deletions(-) mode change 100755 => 100644 services/abilitymgr/include/ability_manager_service.h create mode 100644 services/abilitymgr/include/user_controller.h create mode 100644 services/abilitymgr/include/user_event_handler.h create mode 100644 services/abilitymgr/src/user_controller.cpp create mode 100644 services/abilitymgr/src/user_event_handler.cpp diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 6865fc8bc2f..2d3bd5854bd 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -57,6 +57,10 @@ config("abilityms_config") { "//base/global/i18n_standard/frameworks/intl/include", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", "//base/hiviewdfx/hiview/adapter/utility/include", + "//base/account/os_account/frameworks/common/account_error/include", + "//base/account/os_account/frameworks/common/database/include", + "//base/account/os_account/frameworks/common/log/include", + "//base/account/os_account/interfaces/innerkits/osaccount/native/include", ] cflags = [] if (target_cpu == "arm") { @@ -72,6 +76,7 @@ ohos_shared_library("abilityms") { deps = [ "${innerkits_path}/base:base", "${innerkits_path}/want:want", + "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/global/i18n_standard/frameworks/intl:intl_util", "//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility", "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_native", diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index 9f86004dab7..af51d4df38b 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -90,4 +90,8 @@ abilityms_files = [ "${services_path}/abilitymgr/src/stop_user_callback_proxy.cpp", "${services_path}/abilitymgr/src/stop_user_callback_stub.cpp", "${services_path}/abilitymgr/src/kernal_ability_manager.cpp", + + #multi user + "${services_path}/abilitymgr/src/user_controller.cpp", + "${services_path}/abilitymgr/src/user_event_handler.cpp", ] diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h old mode 100755 new mode 100644 index bf5bee2b625..082b0d62aa0 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -42,6 +42,7 @@ #include "pending_want_manager.h" #include "ams_configuration_parameter.h" #include "event_handler.h" +#include "user_controller.h" namespace OHOS { namespace AAFwk { @@ -305,7 +306,7 @@ public: * * @param userId, user id. */ - void SetStackManager(int userId); + void SetStackManager(int userId, bool switchUser); /** * GetStackManager, get the current stack manager. @@ -580,7 +581,7 @@ public: * * @param userId, user id. */ - void InitMissionListManager(int userId); + void InitMissionListManager(int userId, bool switchUser); virtual sptr GetWantSender( const WantSenderInfo &wantSenderInfo, const sptr &callerToken) override; @@ -756,6 +757,7 @@ public: }; friend class AbilityStackManager; + friend class UserController; protected: void OnAbilityRequestDone(const sptr &token, const int32_t state) override; @@ -868,6 +870,18 @@ private: void DumpFuncInit(); bool CheckCallerIsSystemAppByIpc(); bool IsExistFile(const std::string &path); + + void InitConnectManager(int32_t userId, bool switchUser); + void InitDataAbilityManager(int32_t userId, bool switchUser); + void InitPendWantManager(int32_t userId, bool switchUser); + + // multi user + void StartFreezingScreen(); + void StopFreezingScreen(); + void UserStarted(int32_t userId); + void SwitchToUser(int32_t userId); + void StartLauncherAbility(int32_t userId); + using DumpFuncType = void (AbilityManagerService::*)(const std::string &args, std::vector &info); std::map dumpFuncMap_; @@ -879,10 +893,13 @@ private: ServiceRunningState state_; std::unordered_map> stackManagers_; std::shared_ptr currentStackManager_; + std::unordered_map> connectManagers_; std::shared_ptr connectManager_; sptr iBundleManager_; std::shared_ptr appScheduler_; + std::unordered_map> dataAbilityManagers_; std::shared_ptr dataAbilityManager_; + std::unordered_map> pendingWantManagers_; std::shared_ptr pendingWantManager_; std::shared_ptr systemAppManager_; std::shared_ptr amsConfigResolver_; @@ -896,6 +913,7 @@ private: std::shared_ptr currentMissionListManager_; std::shared_ptr kernalAbilityManager_; sptr snapshotHandler_; + std::shared_ptr userController_; }; } // namespace AAFwk diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 985923f9794..5716ff2df96 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -117,6 +117,7 @@ struct AbilityRequest { Want want; AppExecFwk::AbilityInfo abilityInfo; AppExecFwk::ApplicationInfo appInfo; + int32_t uid = 0; int requestCode = -1; bool restart = false; sptr callerToken; @@ -733,6 +734,8 @@ public: void UpdateConfiguration(const AppExecFwk::Configuration &config) override; int GetId() override; + void SetUid(int32_t uid); + int32_t GetUid(); /** * get the type of ability. @@ -806,6 +809,7 @@ public: AppState appState_ = AppState::BEGIN; int32_t compatibleVersion_ = 0; // > 7 new version, <= 7 old version. + int32_t uid_ = 0; std::weak_ptr missionList_; std::weak_ptr mission_; int32_t missionId_ = -1; diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 10cdd498cfa..35a30294ede 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -99,7 +99,8 @@ public: * @return true on success ,false on failure. */ int LoadAbility(const sptr &token, const sptr &preToken, - const AppExecFwk::AbilityInfo &abilityinfo, const AppExecFwk::ApplicationInfo &application); + const AppExecFwk::AbilityInfo &abilityinfo, const AppExecFwk::ApplicationInfo &application, + int32_t uid); /** * terminate ability with token. @@ -233,6 +234,8 @@ protected: virtual void OnAppStateChanged(const AppExecFwk::AppProcessData &appData) override; private: + std::recursive_mutex lock_; + bool isInit_ {false}; std::weak_ptr callback_; std::unique_ptr appMgrClient_; AppAbilityState appAbilityState_ = AppAbilityState::ABILITY_STATE_UNDEFINED; diff --git a/services/abilitymgr/include/user_controller.h b/services/abilitymgr/include/user_controller.h new file mode 100644 index 00000000000..7fa117bcc56 --- /dev/null +++ b/services/abilitymgr/include/user_controller.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2021 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_AAFWK_USER_CONTROLLER_H +#define OHOS_AAFWK_USER_CONTROLLER_H + +#include +#include +#include + +#include "user_event_handler.h" + +namespace OHOS { +namespace AAFwk { +const int32_t USER_ID_DEFAULT = 0; + +enum UserState { + STATE_BOOTING = 0, + STATE_STARTED, + STATE_STOPPING, + STATE_SHUTDOWN +}; + +class UserItem { +public: + explicit UserItem(int32_t id); + virtual ~UserItem(); + + int32_t GetUserId(); + void SetState(const UserState &state); + UserState GetState(); + +private: + int32_t userId_; + UserState curState_ = STATE_BOOTING; + UserState lastState_ = STATE_BOOTING; +}; + +struct UserEvent { + int32_t oldUserId; + int32_t newUserId; + std::shared_ptr userItem; +}; + +class UserController : public std::enable_shared_from_this { +public: + UserController(); + virtual ~UserController(); + + void Init(); + + /** + * Start user, if it is not running.. + * + * @param userId id of started user. + * @param isForeground whether user should brout to foreground. + * @return 0 if the user has been successfully started. + */ + int32_t StartUser(int32_t userId, bool isForeground); + + /** + * Stop user, if it is running.. + * + * @param userId id of started user. + * @return 0 if the user has been successfully started. + */ + int32_t StopUser(int32_t userId); + + int32_t GetCurrentUserId(); + + std::shared_ptr GetUserItem(int32_t userId); + + void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); + +private: + bool IsCurrentUser(int32_t userId); + bool IsExistOsAccount(int32_t userId); + std::shared_ptr GetOrCreateUserItem(int32_t userId); + void SetCurrentUserId(int32_t userId); + void BroacastUserStarted(int32_t userId); + void MoveUserToForeground(int32_t oldUserId, int32_t newUserId); + void UserBootDone(std::shared_ptr &item); + void BroacastUserBackground(int32_t userId); + void BroacastUserForeground(int32_t userId); + + void SendSystemUserStart(int32_t userId); + void SendSystemUserCurrent(int32_t oldUserId, int32_t newUserId); + void SendReportUserSwitch(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem); + void SendUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem); + void SendContinueUserSwitch(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem); + void SendUserSwitchDone(int32_t userId); + + void HandleSystemUserStart(int32_t userId); + void HandleSystemUserCurrent(int32_t oldUserId, int32_t newUserId); + void HandleReportUserSwitch(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem); + void HandleUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem); + void HandleContinueUserSwitch(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem); + void HandleUserSwitchDone(int32_t userId); + +private: + std::recursive_mutex userLock_; + int32_t currentUserId_ = USER_ID_DEFAULT; + std::unordered_map> userItems_; + std::shared_ptr eventHandler_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_USER_CONTROLLER_H \ No newline at end of file diff --git a/services/abilitymgr/include/user_event_handler.h b/services/abilitymgr/include/user_event_handler.h new file mode 100644 index 00000000000..ad22a2dcc5d --- /dev/null +++ b/services/abilitymgr/include/user_event_handler.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 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_AAFWK_USER_EVENT_HANDLER_H +#define OHOS_AAFWK_USER_EVENT_HANDLER_H + +#include + +#include "event_handler.h" +#include "event_runner.h" + +namespace OHOS { +namespace AAFwk { +class UserController; +class UserEventHandler : public AppExecFwk::EventHandler { +public: + UserEventHandler( + const std::shared_ptr &runner, const std::weak_ptr &owner); + virtual ~UserEventHandler() = default; + + static constexpr uint32_t EVENT_SYSTEM_USER_START = 10; + static constexpr uint32_t EVENT_SYSTEM_USER_CURRENT = 20; + static constexpr uint32_t EVENT_REPORT_USER_SWITCH = 30; + static constexpr uint32_t EVENT_CONTINUE_USER_SWITCH = 40; + static constexpr uint32_t EVENT_USER_SWITCH_TIMEOUT = 50; + static constexpr uint32_t EVENT_REPORT_USER_SWITCH_DONE = 60; + + /** + * ProcessEvent with request. + * + * @param event, inner event loop. + */ + void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; + +private: + std::weak_ptr controller_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_USER_EVENT_HANDLER_H \ No newline at end of file diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 7ef5c48e229..3354409b9ef 100755 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -577,7 +577,7 @@ void AbilityConnectManager::LoadAbility(const std::shared_ptr &ab } } DelayedSingleton::GetInstance()->LoadAbility( - token, perToken, abilityRecord->GetAbilityInfo(), abilityRecord->GetApplicationInfo()); + token, perToken, abilityRecord->GetAbilityInfo(), abilityRecord->GetApplicationInfo(), abilityRecord->GetUid()); abilityRecord->SetStartTime(); } diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 016320bfe55..1ea285e799a 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -89,7 +89,6 @@ AbilityManagerService::AbilityManagerService() eventLoop_(nullptr), handler_(nullptr), state_(ServiceRunningState::STATE_NOT_START), - connectManager_(std::make_shared()), iBundleManager_(nullptr) { std::shared_ptr appScheduler( @@ -132,14 +131,19 @@ bool AbilityManagerService::Init() handler_ = std::make_shared(eventLoop_, weak_from_this()); CHECK_POINTER_RETURN_BOOL(handler_); - CHECK_POINTER_RETURN_BOOL(connectManager_); - connectManager_->SetEventHandler(handler_); + + // init user controller. + userController_ = std::make_shared(); + userController_->Init(); + int userId = GetUserId(); + + InitConnectManager(userId, true); // init ConfigurationDistributor DelayedSingleton::GetInstance(); - auto dataAbilityManager = std::make_shared(); - CHECK_POINTER_RETURN_BOOL(dataAbilityManager); + InitDataAbilityManager(userId, true); + InitPendWantManager(userId, true); amsConfigResolver_ = std::make_shared(); if (amsConfigResolver_) { @@ -148,22 +152,15 @@ bool AbilityManagerService::Init() } useNewMission_ = amsConfigResolver_->IsUseNewMission(); - auto pendingWantManager = std::make_shared(); - if (!pendingWantManager) { - HILOG_ERROR("Failed to init pending want ability manager."); - return false; - } - // after amsConfigResolver_ configuration_ = std::make_shared(); GetGlobalConfiguration(); - int userId = GetUserId(); - SetStackManager(userId); + SetStackManager(userId, true); systemAppManager_ = std::make_shared(userId); CHECK_POINTER_RETURN_BOOL(systemAppManager_); - InitMissionListManager(userId); + InitMissionListManager(userId, true); kernalAbilityManager_ = std::make_shared(userId); CHECK_POINTER_RETURN_BOOL(kernalAbilityManager_); @@ -185,8 +182,6 @@ bool AbilityManagerService::Init() outFile.close(); }; handler_->PostTask(creatWhiteListTask, "creatWhiteList"); - dataAbilityManager_ = dataAbilityManager; - pendingWantManager_ = pendingWantManager; HILOG_INFO("Init success."); return true; } @@ -1841,27 +1836,37 @@ std::shared_ptr AbilityManagerService::GetEventHandler() return handler_; } -void AbilityManagerService::SetStackManager(int userId) +void AbilityManagerService::SetStackManager(int userId, bool switchUser) { auto iterator = stackManagers_.find(userId); if (iterator != stackManagers_.end()) { - currentStackManager_ = iterator->second; + if (switchUser) { + currentStackManager_ = iterator->second; + } } else { - currentStackManager_ = std::make_shared(userId); - currentStackManager_->Init(); - stackManagers_.emplace(userId, currentStackManager_); + auto manager = std::make_shared(userId); + manager->Init(); + stackManagers_.emplace(userId, manager); + if (switchUser) { + currentStackManager_ = manager; + } } } -void AbilityManagerService::InitMissionListManager(int userId) +void AbilityManagerService::InitMissionListManager(int userId, bool switchUser) { auto iterator = missionListManagers_.find(userId); if (iterator != missionListManagers_.end()) { - currentMissionListManager_ = iterator->second; + if (switchUser) { + currentMissionListManager_ = iterator->second; + } } else { - currentMissionListManager_ = std::make_shared(userId); - currentMissionListManager_->Init(); - missionListManagers_.emplace(userId, currentMissionListManager_); + auto manager = std::make_shared(userId); + manager->Init(); + missionListManagers_.emplace(userId, manager); + if (switchUser) { + currentMissionListManager_ = manager; + } } } @@ -1879,6 +1884,9 @@ void AbilityManagerService::DumpWaittingAbilityQueue(std::string &result) // multi user scene int AbilityManagerService::GetUserId() { + if (userController_) { + return userController_->GetCurrentUserId(); + } return DEFAULT_USER_ID; } @@ -1989,7 +1997,9 @@ int AbilityManagerService::GenerateAbilityRequest( auto bms = GetBundleManager(); CHECK_POINTER_AND_RETURN(bms, GET_ABILITY_SERVICE_FAILED); - bms->QueryAbilityInfo(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, 0, request.abilityInfo); + int userId = GetUserId(); + bms->QueryAbilityInfo(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, + userId, request.abilityInfo); if (request.abilityInfo.name.empty() || request.abilityInfo.bundleName.empty()) { HILOG_ERROR("Get ability info failed."); return RESOLVE_ABILITY_ERR; @@ -2018,11 +2028,13 @@ int AbilityManagerService::GenerateAbilityRequest( HILOG_DEBUG("Query app name: %{public}s,", request.appInfo.name.c_str()); AppExecFwk::BundleInfo bundleInfo; - if (!bms->GetBundleInfo(request.appInfo.bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo)) { + if (!bms->GetBundleInfo(request.appInfo.bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, + bundleInfo, userId)) { HILOG_ERROR("Failed to get bundle info when generate ability request."); return RESOLVE_APP_ERR; } request.compatibleVersion = bundleInfo.compatibleVersion; + request.uid = bundleInfo.uid; return ERR_OK; } @@ -2195,7 +2207,8 @@ int AbilityManagerService::PreLoadAppDataAbilities(const std::string &bundleName CHECK_POINTER_AND_RETURN(bms, GET_ABILITY_SERVICE_FAILED); AppExecFwk::BundleInfo bundleInfo; - bool ret = bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo); + int32_t userId = GetUserId(); + bool ret = bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, userId); if (!ret) { HILOG_ERROR("Failed to get bundle info when app data abilities preloading."); return RESOLVE_APP_ERR; @@ -2215,6 +2228,7 @@ int AbilityManagerService::PreLoadAppDataAbilities(const std::string &bundleName return ERR_TIMED_OUT; } dataAbilityRequest.abilityInfo = *it; + dataAbilityRequest.uid = bundleInfo.uid; HILOG_INFO("App data ability preloading: '%{public}s.%{public}s'...", it->bundleName.c_str(), it->name.c_str()); auto dataAbility = dataAbilityManager_->Acquire(dataAbilityRequest, false, nullptr, false); @@ -2795,5 +2809,91 @@ int32_t AbilityManagerService::GetMissionSnapshot(const std::string& deviceId, i missionSnapshot.snapshot = snapshot.GetPixelMap(); return result; } + +void AbilityManagerService::StartFreezingScreen() +{ + HILOG_DEBUG("%{public}s", __func__); +} + +void AbilityManagerService::StopFreezingScreen() +{ + HILOG_DEBUG("%{public}s", __func__); +} + +void AbilityManagerService::UserStarted(int32_t userId) +{ + HILOG_DEBUG("%{public}s", __func__); + InitConnectManager(userId, false); + SetStackManager(userId, false); + InitMissionListManager(userId, false); + InitDataAbilityManager(userId, false); + InitPendWantManager(userId, false); +} + +void AbilityManagerService::SwitchToUser(int32_t userId) +{ + HILOG_DEBUG("%{public}s", __func__); + InitConnectManager(userId, true); + SetStackManager(userId, true); + InitMissionListManager(userId, true); + InitDataAbilityManager(userId, true); + InitPendWantManager(userId, true); +} + +void AbilityManagerService::StartLauncherAbility(int32_t userId) +{ + HILOG_DEBUG("StartLauncherAbility, userId:%{public}d, currentUserId:%{public}d", userId, GetUserId()); + ConnectBmsService(); + StartingLauncherAbility(); +} + +void AbilityManagerService::InitConnectManager(int32_t userId, bool switchUser) +{ + auto it = connectManagers_.find(userId); + if (it == connectManagers_.end()) { + auto manager = std::make_shared(); + manager->SetEventHandler(handler_); + connectManagers_.emplace(userId, manager); + if (switchUser) { + connectManager_ = manager; + } + } else { + if (switchUser) { + connectManager_ = it->second; + } + } +} + +void AbilityManagerService::InitDataAbilityManager(int32_t userId, bool switchUser) +{ + auto it = dataAbilityManagers_.find(userId); + if (it == dataAbilityManagers_.end()) { + auto manager = std::make_shared(); + dataAbilityManagers_.emplace(userId, manager); + if (switchUser) { + dataAbilityManager_ = manager; + } + } else { + if (switchUser) { + dataAbilityManager_ = it->second; + } + } +} + +void AbilityManagerService::InitPendWantManager(int32_t userId, bool switchUser) +{ + auto it = pendingWantManagers_.find(userId); + if (it == pendingWantManagers_.end()) { + auto manager = std::make_shared(); + pendingWantManagers_.emplace(userId, manager); + if (switchUser) { + pendingWantManager_ = manager; + } + } else { + if (switchUser) { + pendingWantManager_ = it->second; + } + } +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 31b20b5d720..aa3abd3f8c9 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -111,6 +111,7 @@ std::shared_ptr AbilityRecord::CreateAbilityRecord(const AbilityR abilityRequest.appInfo, abilityRequest.requestCode, abilityRequest.compatibleVersion); } CHECK_POINTER_AND_RETURN(abilityRecord, nullptr); + abilityRecord->SetUid(abilityRequest.uid); if (!abilityRecord->Init()) { HILOG_ERROR("failed to init new ability record"); return nullptr; @@ -136,6 +137,16 @@ bool AbilityRecord::Init() return true; } +void AbilityRecord::SetUid(int32_t uid) +{ + uid_ = uid; +} + +int32_t AbilityRecord::GetUid() +{ + return uid_; +} + int AbilityRecord::LoadAbility() { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -160,7 +171,7 @@ int AbilityRecord::LoadAbility() callerToken_ = callerList_.back()->GetCaller()->GetToken(); } return DelayedSingleton::GetInstance()->LoadAbility( - token_, callerToken_, abilityInfo_, applicationInfo_); + token_, callerToken_, abilityInfo_, applicationInfo_, uid_); } void AbilityRecord::ForegroundAbility() diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 7a6b868ad66..5a09640484d 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -35,6 +35,11 @@ bool AppScheduler::Init(const std::weak_ptr &callback) CHECK_POINTER_RETURN_BOOL(callback.lock()); CHECK_POINTER_RETURN_BOOL(appMgrClient_); + std::lock_guard guard(lock_); + if (isInit_) { + return true; + } + callback_ = callback; /* because the errcode type of AppMgr Client API will be changed to int, * so must to covert the return result */ @@ -50,17 +55,19 @@ bool AppScheduler::Init(const std::weak_ptr &callback) return false; } HILOG_INFO("success to ConnectAppMgrService"); + isInit_ = true; return true; } int AppScheduler::LoadAbility(const sptr &token, const sptr &preToken, - const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo) + const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo, + int32_t uid) { HILOG_DEBUG("Load ability."); CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); /* because the errcode type of AppMgr Client API will be changed to int, * so must to covert the return result */ - int ret = static_cast(appMgrClient_->LoadAbility(token, preToken, abilityInfo, applicationInfo)); + int ret = static_cast(appMgrClient_->LoadAbility(token, preToken, abilityInfo, applicationInfo, uid)); if (ret != ERR_OK) { HILOG_ERROR("AppScheduler fail to LoadAbility. ret %d", ret); return INNER_ERR; diff --git a/services/abilitymgr/src/user_controller.cpp b/services/abilitymgr/src/user_controller.cpp new file mode 100644 index 00000000000..8fe353d91b2 --- /dev/null +++ b/services/abilitymgr/src/user_controller.cpp @@ -0,0 +1,445 @@ +/* + * Copyright (c) 2021 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 "user_controller.h" + +#include "ability_manager_service.h" +#include "hilog_wrapper.h" +#include "ipc_skeleton.h" +#include "os_account_manager.h" + +namespace OHOS { +namespace AAFwk { +using namespace OHOS::AppExecFwk; +namespace { +const int64_t USER_SWITCH_TIMEOUT = 3 * 1000; // 3s + +class Holder { +public: + Holder() + { + identity_ = IPCSkeleton::ResetCallingIdentity(); + } + + ~Holder() + { + IPCSkeleton::SetCallingIdentity(identity_); + } + +private: + std::string identity_; +}; +} + +UserItem::UserItem(int32_t id) : userId_(id) +{} + +UserItem::~UserItem() {} + +int32_t UserItem::GetUserId() +{ + return userId_; +} + +void UserItem::SetState(const UserState &state) +{ + if (curState_ == state) { + return; + } + lastState_ = curState_; + curState_ = state; +} + +UserState UserItem::GetState() +{ + return curState_; +} + +UserController::UserController() +{ +} + +UserController::~UserController() +{ +} + +void UserController::Init() +{ + auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); + if (!handler) { + return; + } + + auto runner = handler->GetEventRunner(); + if (!runner) { + return; + } + + if (eventHandler_) { + return; + } + eventHandler_ = std::make_shared(runner, shared_from_this()); +} + +int32_t UserController::StartUser(int32_t userId, bool isForeground) +{ + if (userId < 0 || userId == USER_ID_DEFAULT) { + HILOG_ERROR("StartUser userId is invalid:%{public}d", userId); + return -1; + } + + if (IsCurrentUser(userId)) { + HILOG_WARN("StartUser user is already current:%{public}d", userId); + return 0; + } + + if (!IsExistOsAccount(userId)) { + HILOG_ERROR("StartUser not exist such account:%{public}d", userId); + return -1; + } + + if (isForeground) { + // start freezing screen + DelayedSingleton::GetInstance()->StartFreezingScreen(); + } + + auto oldUserId = GetCurrentUserId(); + auto userItem = GetOrCreateUserItem(userId); + auto state = userItem->GetState(); + if (state == STATE_STOPPING || state == STATE_SHUTDOWN) { + HILOG_ERROR("StartUser user is stop now, userId:%{public}d", userId); + return -1; + } + + if (isForeground) { + SetCurrentUserId(userId); + // todo : notify wms switching now + } + + bool needStart = false; + if (state == STATE_BOOTING) { + needStart = true; + // send user start msg. + SendSystemUserStart(userId); + } + + if (isForeground) { + SendSystemUserCurrent(oldUserId, userId); + SendReportUserSwitch(oldUserId, userId, userItem); + SendUserSwitchTimeout(oldUserId, userId, userItem); + } + + if (needStart) { + BroacastUserStarted(userId); + } + + UserBootDone(userItem); + if (isForeground) { + MoveUserToForeground(oldUserId, userId); + } + + return 0; +} + +int32_t UserController::StopUser(int32_t userId) +{ + return -1; +} + +int32_t UserController::GetCurrentUserId() +{ + std::lock_guard guard(userLock_); + return currentUserId_; +} + +std::shared_ptr UserController::GetUserItem(int32_t userId) +{ + std::lock_guard guard(userLock_); + auto it = userItems_.find(userId); + if (it != userItems_.end()) { + return it->second; + } + + return nullptr; +} + +bool UserController::IsCurrentUser(int32_t userId) +{ + int32_t oldUserId = GetCurrentUserId(); + if (oldUserId == userId) { + auto userItem = GetUserItem(userId); + if (userItem) { + HILOG_WARN("IsCurrentUser userId is already current:%{public}d", userId); + return true; + } + } + return false; +} + +bool UserController::IsExistOsAccount(int32_t userId) +{ + bool isExist = false; + auto errCode = AccountSA::OsAccountManager::IsOsAccountExists(userId, isExist); + return (errCode == 0) && isExist; +} + +std::shared_ptr UserController::GetOrCreateUserItem(int32_t userId) +{ + std::lock_guard guard(userLock_); + auto it = userItems_.find(userId); + if (it != userItems_.end()) { + return it->second; + } + + auto userItem = std::make_shared(userId); + userItems_.emplace(userId, userItem); + return userItem; +} + +void UserController::SetCurrentUserId(int32_t userId) +{ + std::lock_guard guard(userLock_); + currentUserId_ = userId; +} + +void UserController::MoveUserToForeground(int32_t oldUserId, int32_t newUserId) +{ + auto ams = DelayedSingleton::GetInstance(); + if (!ams) { + return; + } + ams->SwitchToUser(newUserId); + ams->StartLauncherAbility(newUserId); + BroacastUserBackground(oldUserId); + BroacastUserForeground(newUserId); +} + +void UserController::UserBootDone(std::shared_ptr &item) +{ + if (!item) { + return; + } + int32_t userId = item->GetUserId(); + + std::lock_guard guard(userLock_); + auto it = userItems_.find(userId); + if (it != userItems_.end()) { + return; + } + + if (item != it->second) { + return; + } + item->SetState(UserState::STATE_STARTED); + auto ams = DelayedSingleton::GetInstance(); + if (!ams) { + return; + } + ams->UserStarted(userId); +} + +void UserController::BroacastUserStarted(int32_t userId) +{ + // todo: broadcast event user start. +} + +void UserController::BroacastUserBackground(int32_t userId) +{ + // todo: broadcast event user switch to bg. +} + +void UserController::BroacastUserForeground(int32_t userId) +{ + // todo: broadcast event user switch to fg. +} + +void UserController::SendSystemUserStart(int32_t userId) +{ + auto handler = eventHandler_; + if (!handler) { + return; + } + + std::shared_ptr eventData = std::make_shared(); + eventData->newUserId = userId; + auto event = InnerEvent::Get(UserEventHandler::EVENT_SYSTEM_USER_START, eventData); + handler->SendEvent(event); +} + +void UserController::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) +{ + if (!event) { + return; + } + + auto eventId = event->GetInnerEventId(); + auto eventData = event->GetSharedObject(); + if (!eventData) { + HILOG_DEBUG("no event data, event id: %{public}u.", eventId); + return; + } + + HILOG_DEBUG("Event id obtained: %{public}u.", eventId); + switch (eventId) { + case UserEventHandler::EVENT_SYSTEM_USER_START: { + HandleSystemUserStart(eventData->newUserId); + break; + } + case UserEventHandler::EVENT_SYSTEM_USER_CURRENT: { + HandleSystemUserCurrent(eventData->oldUserId, eventData->newUserId); + break; + } + case UserEventHandler::EVENT_REPORT_USER_SWITCH: { + HandleReportUserSwitch(eventData->oldUserId, eventData->newUserId, eventData->userItem); + break; + } + case UserEventHandler::EVENT_CONTINUE_USER_SWITCH: { + HandleContinueUserSwitch(eventData->oldUserId, eventData->newUserId, eventData->userItem); + break; + } + case UserEventHandler::EVENT_USER_SWITCH_TIMEOUT: { + HandleUserSwitchTimeout(eventData->oldUserId, eventData->newUserId, eventData->userItem); + break; + } + case UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE: { + HandleUserSwitchDone(eventData->newUserId); + break; + } + default: { + HILOG_WARN("Unsupported event."); + break; + } + } +} + +void UserController::SendSystemUserCurrent(int32_t oldUserId, int32_t newUserId) +{ + auto handler = eventHandler_; + if (!handler) { + return; + } + + std::shared_ptr eventData = std::make_shared(); + eventData->oldUserId = oldUserId; + eventData->newUserId = newUserId; + auto event = InnerEvent::Get(UserEventHandler::EVENT_SYSTEM_USER_CURRENT, eventData); + handler->SendEvent(event); +} + +void UserController::SendReportUserSwitch(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem) +{ + auto handler = eventHandler_; + if (!handler) { + return; + } + + handler->RemoveEvent(UserEventHandler::EVENT_REPORT_USER_SWITCH); + std::shared_ptr eventData = std::make_shared(); + eventData->oldUserId = oldUserId; + eventData->newUserId = newUserId; + eventData->userItem = usrItem; + auto event = InnerEvent::Get(UserEventHandler::EVENT_REPORT_USER_SWITCH, eventData); + handler->SendEvent(event); +} + +void UserController::SendUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem) +{ + auto handler = eventHandler_; + if (!handler) { + return; + } + + handler->RemoveEvent(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT); + std::shared_ptr eventData = std::make_shared(); + eventData->oldUserId = oldUserId; + eventData->newUserId = newUserId; + eventData->userItem = usrItem; + auto event = InnerEvent::Get(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT, eventData); + handler->SendEvent(event, USER_SWITCH_TIMEOUT); +} + +void UserController::SendContinueUserSwitch(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem) +{ + auto handler = eventHandler_; + if (!handler) { + return; + } + + handler->RemoveEvent(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT); + std::shared_ptr eventData = std::make_shared(); + eventData->oldUserId = oldUserId; + eventData->newUserId = newUserId; + eventData->userItem = usrItem; + auto event = InnerEvent::Get(UserEventHandler::EVENT_CONTINUE_USER_SWITCH, eventData); + handler->SendEvent(event); +} + +void UserController::SendUserSwitchDone(int32_t userId) +{ + auto handler = eventHandler_; + if (!handler) { + return; + } + + handler->RemoveEvent(UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE); + std::shared_ptr eventData = std::make_shared(); + eventData->newUserId = userId; + auto event = InnerEvent::Get(UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE, eventData); + handler->SendEvent(event); +} + +void UserController::HandleSystemUserStart(int32_t userId) +{ + // todo : notify system mgr user start. +} + +void UserController::HandleSystemUserCurrent(int32_t oldUserId, int32_t newUserId) +{ + // todo : notify system mgr user switch to new. +} + +void UserController::HandleReportUserSwitch(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem) +{ + // todo : notify user switch observers, not support yet. +} + +void UserController::HandleUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem) +{ + // todo : other observers + SendContinueUserSwitch(oldUserId, newUserId, usrItem); +} + +void UserController::HandleContinueUserSwitch(int32_t oldUserId, int32_t newUserId, + std::shared_ptr &usrItem) +{ + auto ams = DelayedSingleton::GetInstance(); + if (ams) { + ams->StopFreezingScreen(); + } + SendUserSwitchDone(newUserId); +} + +void UserController::HandleUserSwitchDone(int32_t userId) +{ + // todo : notify wms switching done. + // todo : notify user switch observers. +} +} +} diff --git a/services/abilitymgr/src/user_event_handler.cpp b/services/abilitymgr/src/user_event_handler.cpp new file mode 100644 index 00000000000..c701713518f --- /dev/null +++ b/services/abilitymgr/src/user_event_handler.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 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 "user_event_handler.h" + +#include "user_controller.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AAFwk { +UserEventHandler::UserEventHandler( + const std::shared_ptr &runner, const std::weak_ptr &owner) + : AppExecFwk::EventHandler(runner), controller_(owner) +{ +} + +void UserEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) +{ + if (!event) { + HILOG_ERROR("invalid event"); + return; + } + + auto owner = controller_.lock(); + if (owner) { + owner->ProcessEvent(event); + } +} +} // namespace AAFwk +} // namespace OHOS diff --git a/services/abilitymgr/test/BUILD.gn b/services/abilitymgr/test/BUILD.gn index 46829a95314..a782a35ef33 100644 --- a/services/abilitymgr/test/BUILD.gn +++ b/services/abilitymgr/test/BUILD.gn @@ -82,6 +82,8 @@ ohos_source_set("abilityms_test_source") { "${services_path}/abilitymgr/src/stack_info.cpp", "${services_path}/abilitymgr/src/stack_setting.cpp", "${services_path}/abilitymgr/src/task_data_persistence_mgr.cpp", + "${services_path}/abilitymgr/src/user_controller.cpp", + "${services_path}/abilitymgr/src/user_event_handler.cpp", "${services_path}/abilitymgr/src/want_receiver_proxy.cpp", "${services_path}/abilitymgr/src/want_receiver_stub.cpp", "${services_path}/abilitymgr/src/want_sender_info.cpp", @@ -99,6 +101,10 @@ ohos_source_set("abilityms_test_source") { "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/appmgr", "//foundation/aafwk/standard/interfaces/innerkits/dataobs_manager/include", + "//base/account/os_account/frameworks/common/account_error/include", + "//base/account/os_account/frameworks/common/database/include", + "//base/account/os_account/frameworks/common/log/include", + "//base/account/os_account/interfaces/innerkits/osaccount/native/include", ] external_dependent_files = [ @@ -122,6 +128,7 @@ ohos_source_set("abilityms_test_source") { "${innerkits_path}/base:base", "${innerkits_path}/want:want", "${services_path}/abilitymgr/test/mock/libs/sa_mgr:sa_mgr_mock", + "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/global/i18n_standard/frameworks/intl:intl_util", "//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", diff --git a/services/abilitymgr/test/mock/include/mock_app_manager_client.h b/services/abilitymgr/test/mock/include/mock_app_manager_client.h index b05c3802034..3a1d2a59b45 100644 --- a/services/abilitymgr/test/mock/include/mock_app_manager_client.h +++ b/services/abilitymgr/test/mock/include/mock_app_manager_client.h @@ -28,8 +28,8 @@ public: {} ~MockAppMgrClient() {} - MOCK_METHOD4(LoadAbility, AppMgrResultCode(const sptr &token, const sptr &preToken, - const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo)); + MOCK_METHOD5(LoadAbility, AppMgrResultCode(const sptr &token, const sptr &preToken, + const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo, int32_t uid)); MOCK_METHOD1(TerminateAbility, AppMgrResultCode(const sptr &)); MOCK_METHOD2(UpdateAbilityState, AppMgrResultCode(const sptr &token, const AbilityState state)); diff --git a/services/abilitymgr/test/mock/include/mock_app_mgr_client.h b/services/abilitymgr/test/mock/include/mock_app_mgr_client.h index 102804069df..1c1ba629bc1 100644 --- a/services/abilitymgr/test/mock/include/mock_app_mgr_client.h +++ b/services/abilitymgr/test/mock/include/mock_app_mgr_client.h @@ -29,7 +29,7 @@ public: virtual ~MockAppMgrClient() {}; virtual AppMgrResultCode LoadAbility(const sptr &token, const sptr &preToken, - const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo) + const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo, int32_t uid) { HILOG_INFO("MockAppMgrClient LoadAbility enter."); token_ = token; diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h index 2688800e3b0..71ac01703ba 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h @@ -42,7 +42,7 @@ public: * @return Returns RESULT_OK on success, others on failure. */ virtual AppMgrResultCode LoadAbility(const sptr &token, const sptr &preToken, - const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo); + const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo, int32_t uid); /** * Terminate ability. diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp index 6fc4637e106..657293e5a89 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp @@ -35,7 +35,7 @@ AppMgrClient::~AppMgrClient() {} AppMgrResultCode AppMgrClient::LoadAbility(const sptr &token, const sptr &preToken, - const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo) + const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo, int32_t uid) { return AppMgrResultCode::RESULT_OK; } diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp index 596295ec13f..fa0f4328e76 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp @@ -43,7 +43,8 @@ bool AppScheduler::Init(const std::weak_ptr &callback) } int AppScheduler::LoadAbility(const sptr &token, const sptr &preToken, - const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo) + const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo, + int32_t uid) { HILOG_INFO("Test AppScheduler::LoadAbility()"); if (applicationInfo.bundleName.find("com.ix.First.Test") != std::string::npos) { diff --git a/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp b/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp index e711dfd8d7b..e44e936e867 100644 --- a/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp @@ -141,7 +141,7 @@ void AbilityDumpTest::OnStartAms() EXPECT_TRUE(g_abilityMs->pendingWantManager_); int userId = g_abilityMs->GetUserId(); - g_abilityMs->SetStackManager(userId); + g_abilityMs->SetStackManager(userId, true); g_abilityMs->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(g_abilityMs->systemAppManager_); @@ -558,4 +558,4 @@ HWTEST_F(AbilityDumpTest, Ability_Dump_013, TestSize.Level2) GTEST_LOG_(INFO) << "Ability_Dump_013 end"; } } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp index d85093bf6fc..1bea8f98ddf 100755 --- a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp @@ -147,7 +147,7 @@ void AbilityManagerServiceTest::OnStartAms() abilityMs_->GetGlobalConfiguration(); int userId = abilityMs_->GetUserId(); - abilityMs_->SetStackManager(userId); + abilityMs_->SetStackManager(userId, true); abilityMs_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs_->systemAppManager_); @@ -615,7 +615,7 @@ HWTEST_F(AbilityManagerServiceTest, Interface_012, TestSize.Level1) */ HWTEST_F(AbilityManagerServiceTest, Interface_013, TestSize.Level1) { - abilityMs_->SetStackManager(0); + abilityMs_->SetStackManager(0, true); EXPECT_NE(nullptr, abilityMs_->GetStackManager()); } diff --git a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp index 7c8547bc4e8..81a9e356636 100644 --- a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp @@ -100,7 +100,7 @@ void AbilityStackManagerTest::OnStartabilityMs() EXPECT_TRUE(abilityMs_->pendingWantManager_); int userId = abilityMs_->GetUserId(); - abilityMs_->SetStackManager(userId); + abilityMs_->SetStackManager(userId, true); abilityMs_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs_->systemAppManager_); diff --git a/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp b/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp index d59933c3acc..25ccafc9ab1 100644 --- a/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp @@ -110,7 +110,7 @@ void AbilityWithApplicationsTest::OnStartabilityAms() EXPECT_TRUE(abilityMs_->pendingWantManager_); int userId = abilityMs_->GetUserId(); - abilityMs_->SetStackManager(userId); + abilityMs_->SetStackManager(userId, true); abilityMs_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs_->systemAppManager_); @@ -380,4 +380,4 @@ HWTEST_F(AbilityWithApplicationsTest, Teminate_Ability_With_Applications_002, Te GTEST_LOG_(INFO) << "Teminate_Ability_With_Applications_002 end"; } } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp b/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp index b3214d77cbf..228314d13d0 100644 --- a/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp +++ b/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp @@ -119,7 +119,7 @@ void AbilityMsAppmsTest::OnStartabilityAms() EXPECT_TRUE(abilityMs_->pendingWantManager_); int userId = abilityMs_->GetUserId(); - abilityMs_->SetStackManager(userId); + abilityMs_->SetStackManager(userId, true); abilityMs_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs_->systemAppManager_); @@ -324,4 +324,4 @@ HWTEST_F(AbilityMsAppmsTest, AaFwk_AbilityMS_AppMS_005, TestSize.Level1) GTEST_LOG_(INFO) << "AbilityMsAppMsTest_AaFwk_AbilityMS_AppMS_005 end"; } } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/abilitymgr/test/unittest/phone/app_scheduler_test/app_scheduler_test.cpp b/services/abilitymgr/test/unittest/phone/app_scheduler_test/app_scheduler_test.cpp index 01ce6281628..724f6f6446f 100644 --- a/services/abilitymgr/test/unittest/phone/app_scheduler_test/app_scheduler_test.cpp +++ b/services/abilitymgr/test/unittest/phone/app_scheduler_test/app_scheduler_test.cpp @@ -128,7 +128,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_oprator_003, TestSize.Level1) EXPECT_EQ((int)ERR_OK, DelayedSingleton::GetInstance()->LoadAbility( - token, pretoken, record->GetAbilityInfo(), record->GetApplicationInfo())); + token, pretoken, record->GetAbilityInfo(), record->GetApplicationInfo(), 0)); } /* @@ -159,7 +159,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_oprator_004, TestSize.Level1) DelayedSingleton::GetInstance()->appMgrClient_ = nullptr; EXPECT_NE((int)ERR_OK, DelayedSingleton::GetInstance()->LoadAbility( - token, pretoken, record->GetAbilityInfo(), record->GetApplicationInfo())); + token, pretoken, record->GetAbilityInfo(), record->GetApplicationInfo(), 0)); } /* @@ -465,4 +465,4 @@ HWTEST_F(AppSchedulerTest, AppScheduler_oprator_017, TestSize.Level1) DelayedSingleton::GetInstance()->KillProcessByAbilityToken(token); } } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp b/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp index d516a84db4d..229040dfdf7 100644 --- a/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp +++ b/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp @@ -119,7 +119,7 @@ void LifecycleTest::OnStartabilityAms() EXPECT_TRUE(abilityMs_->pendingWantManager_); int userId = abilityMs_->GetUserId(); - abilityMs_->SetStackManager(userId); + abilityMs_->SetStackManager(userId, true); abilityMs_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs_->systemAppManager_); @@ -630,4 +630,4 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_007, TestSize.Leve } } } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp b/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp index c03c2818c39..fcc6f63efa8 100644 --- a/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp +++ b/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp @@ -153,7 +153,7 @@ void TerminateAbilityTest::OnStartAms() EXPECT_TRUE(g_aams->pendingWantManager_); int userId = g_aams->GetUserId(); - g_aams->SetStackManager(userId); + g_aams->SetStackManager(userId, true); g_aams->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(g_aams->systemAppManager_); @@ -784,4 +784,4 @@ HWTEST_F(TerminateAbilityTest, AAFWK_g_aamsTerminateAbility_014, TestSize.Level1 EXPECT_EQ(g_aams->TerminateAbility(token, -1, nullptr), 0); } } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/test/mock/include/mock_app_mgr_client.h b/services/test/mock/include/mock_app_mgr_client.h index 47aefe463a8..b005e7f5dac 100644 --- a/services/test/mock/include/mock_app_mgr_client.h +++ b/services/test/mock/include/mock_app_mgr_client.h @@ -25,8 +25,8 @@ class MockAppMgrClient : public AppMgrClient { public: MockAppMgrClient(); ~MockAppMgrClient(); - MOCK_METHOD4(LoadAbility, AppMgrResultCode(const sptr &, const sptr &, - const AbilityInfo &, const ApplicationInfo &)); + MOCK_METHOD5(LoadAbility, AppMgrResultCode(const sptr &, const sptr &, + const AbilityInfo &, const ApplicationInfo &, int32_t uid)); MOCK_METHOD1(TerminateAbility, AppMgrResultCode(const sptr &)); MOCK_METHOD2(UpdateAbilityState, AppMgrResultCode(const sptr &token, const AbilityState state)); MOCK_METHOD1(KillApplication, AppMgrResultCode(const std::string &)); diff --git a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp index 2e5de6b2087..ce728edb34e 100644 --- a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp +++ b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp @@ -190,7 +190,7 @@ static void OnStartAms() AbilityMgrModuleTest::abilityMgrServ_->GetGlobalConfiguration(); int userId = AbilityMgrModuleTest::abilityMgrServ_->GetUserId(); - AbilityMgrModuleTest::abilityMgrServ_->SetStackManager(userId); + AbilityMgrModuleTest::abilityMgrServ_->SetStackManager(userId, true); AbilityMgrModuleTest::abilityMgrServ_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(AbilityMgrModuleTest::abilityMgrServ_->systemAppManager_); @@ -285,7 +285,7 @@ std::shared_ptr AbilityMgrModuleTest::GreatePageAbility( const std::string &abilityName, const std::string &bundleName) { Want want = CreateWant(abilityName, bundleName); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); int testRequestCode = 1; SetActive(); abilityMgrServ_->StartAbility(want, testRequestCode); @@ -329,7 +329,8 @@ void AbilityMgrModuleTest::MockDataAbilityLoadHandlerInner(bool &testFailed, spt const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo) { + const ApplicationInfo &appInfo, + int32_t uid) { dataAbilityToken = token; testFailed = testFailed || (abilityInfo.type != AbilityType::DATA); std::thread(&AbilityManagerService::AttachAbilityThread, abilityMgrServ.get(), mockDataAbilityScheduler, token) @@ -337,7 +338,7 @@ void AbilityMgrModuleTest::MockDataAbilityLoadHandlerInner(bool &testFailed, spt return AppMgrResultCode::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockLoadAbility)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockLoadAbility)); int counts = 2; EXPECT_CALL(*mockAppMgrClient_, UpdateAbilityState(_, _)) .Times(counts) @@ -385,14 +386,15 @@ void AbilityMgrModuleTest::MockServiceAbilityLoadHandlerInner( auto mockHandler = [&testResult, &bundleName, &abilityName, &testToken](const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo) { + const ApplicationInfo &appInfo, + int32_t uid) { testToken = token; testResult = !!testToken && abilityInfo.bundleName == bundleName && abilityInfo.name == abilityName && appInfo.bundleName == bundleName; return AppMgrResultCode::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); } void AbilityMgrModuleTest::CreateServiceRecord(std::shared_ptr &record, Want &want, @@ -547,14 +549,15 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_001, TestSize.Level1) auto mockHandler = [&](const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo) { + const ApplicationInfo &appInfo, + int32_t uid) { testToken = token; testResult = !!testToken && abilityInfo.bundleName == bundleName && abilityInfo.name == abilityName && appInfo.bundleName == bundleName; return AppMgrResultCode::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); @@ -912,7 +915,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_009, TestSize.Level1) const sptr callback(new AbilityConnectionProxy(stub)); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); abilityMgrServ_->ConnectAbility(want, callback, nullptr); std::shared_ptr record = abilityMgrServ_->connectManager_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -976,7 +979,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_010, TestSize.Level1) abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(2); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(2); abilityMgrServ_->ConnectAbility(want1, callback1, nullptr); abilityMgrServ_->ConnectAbility(want2, callback1, nullptr); abilityMgrServ_->ConnectAbility(want1, callback2, nullptr); @@ -1036,13 +1039,14 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_011, TestSize.Level1) auto mockHandler = [&](const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo) { + const ApplicationInfo &appInfo, + int32_t uid) { testToken = token; testResult = !!testToken && abilityInfo.bundleName == bundleName && abilityInfo.name == abilityName && appInfo.bundleName == bundleName; return AppMgrResultCode::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); int testRequestCode = 123; SetActive(); @@ -1107,13 +1111,14 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_012, TestSize.Level1) auto mockHandler = [&](const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo) { + const ApplicationInfo &appInfo, + int32_t uid) { testToken = token; testResult = !!testToken && abilityInfo.bundleName == bundleName && abilityInfo.name == abilityName && appInfo.bundleName == bundleName; return AppMgrResultCode::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); @@ -1184,7 +1189,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_013, TestSize.Level1) Want want2 = CreateWant(abilityName2, bundleName2); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(2); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(2); int testRequestCode = 123; abilityMgrServ_->StartAbility(want1, testRequestCode); abilityMgrServ_->StartAbility(want2, testRequestCode); @@ -1217,7 +1222,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_014, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); std::shared_ptr record = abilityMgrServ_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -1263,7 +1268,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_015, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); std::shared_ptr record = abilityMgrServ_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -1308,7 +1313,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_016, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); std::shared_ptr record = abilityMgrServ_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -1357,7 +1362,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_017, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); std::shared_ptr record = abilityMgrServ_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -1406,7 +1411,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_018, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); int testRequestCode = 123; SetActive(); abilityMgrServ_->StartAbility(want, testRequestCode); @@ -1477,7 +1482,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_019, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); EXPECT_TRUE(abilityMgrServ_); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); std::shared_ptr record = abilityMgrServ_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -1547,7 +1552,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_020, TestSize.Level3) sptr stub(new MockAbilityConnectCallbackStub()); const sptr callback(new AbilityConnectionProxy(stub)); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); abilityMgrServ_->ConnectAbility(want, callback, nullptr); EXPECT_EQ((std::size_t)1, abilityMgrServ_->connectManager_->connectMap_.size()); EXPECT_EQ((std::size_t)1, abilityMgrServ_->connectManager_->serviceMap_.size()); @@ -1594,7 +1599,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_021, TestSize.Level1) Want want2 = CreateWant(abilityName2, bundleName2); sptr scheduler = new MockAbilityScheduler(); EXPECT_TRUE(scheduler); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(2); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(2); EXPECT_CALL(*mockAppMgrClient_, AbilityAttachTimeOut(_)).Times(1); EXPECT_CALL(*mockAppMgrClient_, UpdateAbilityState(_, _)).Times(2); EXPECT_CALL(*scheduler, ScheduleAbilityTransaction(_, _)).Times(1); @@ -1640,7 +1645,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_022, TestSize.Level1) Want want2 = CreateWant(abilityName2, bundleName2); sptr scheduler = new MockAbilityScheduler(); EXPECT_TRUE(scheduler); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(2); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(2); EXPECT_CALL(*mockAppMgrClient_, AbilityAttachTimeOut(_)).Times(1); EXPECT_CALL(*mockAppMgrClient_, UpdateAbilityState(_, _)).Times(1); EXPECT_CALL(*scheduler, ScheduleAbilityTransaction(_, _)).Times(2); @@ -1677,7 +1682,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_023, TestSize.Level1) EXPECT_TRUE(abilityMgrServ_); EXPECT_TRUE(mockAppMgrClient_); ClearStack(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); Want want = CreateWant("RadioTopAbility", COM_IX_HIRADIO); abilityMgrServ_->StartAbility(want); auto testAbilityRecord = GetTopAbility(); @@ -1705,7 +1710,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_024, TestSize.Level1) auto stackManager = abilityMgrServ_->GetStackManager(); EXPECT_TRUE(stackManager); sptr scheduler = new MockAbilityScheduler(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); EXPECT_CALL(*scheduler, ScheduleAbilityTransaction(_, _)).Times(1); EXPECT_CALL(*scheduler, AsObject()).Times(2); Want want = CreateWant("PhoneAbility1", COM_IX_PHONE); @@ -1806,7 +1811,7 @@ HWTEST_F(AbilityMgrModuleTest, UpdateConfiguration_028, TestSize.Level1) std::string bundleName = "com.ix.hiMusic"; SetActive(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); EXPECT_CALL(*mockAppMgrClient_, UpdateAbilityState(_, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); Want want = CreateWant(abilityName, bundleName); auto startRef = abilityMgrServ_->StartAbility(want); @@ -1864,7 +1869,7 @@ HWTEST_F(AbilityMgrModuleTest, UpdateConfiguration_029, TestSize.Level1) std::string bundleName = "com.ix.hiService"; SetActive(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); EXPECT_CALL(*mockAppMgrClient_, UpdateAbilityState(_, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); Want want = CreateWant(abilityName, bundleName); auto startRef = abilityMgrServ_->StartAbility(want); diff --git a/services/test/moduletest/ability_record_test/ability_record_module_test.cpp b/services/test/moduletest/ability_record_test/ability_record_module_test.cpp index 46e23d75fc9..4f9acc51469 100644 --- a/services/test/moduletest/ability_record_test/ability_record_module_test.cpp +++ b/services/test/moduletest/ability_record_test/ability_record_module_test.cpp @@ -239,7 +239,8 @@ HWTEST_F(AbilityRecordModuleTest, LoadAbility_001, TestSize.Level3) auto mockHandler = [&](const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo) { + const ApplicationInfo &appInfo, + int32_t uid) { if (abilityInfo != abilityRequest.abilityInfo) { return static_cast(ERR_INVALID_VALUE); } @@ -249,7 +250,7 @@ HWTEST_F(AbilityRecordModuleTest, LoadAbility_001, TestSize.Level3) return AppExecFwk::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); + EXPECT_CALL(*mockAppMgrClient, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); auto appScheduler = DelayedSingleton::GetInstance(); auto backupAppMgrClient = std::move(appScheduler->appMgrClient_); @@ -711,4 +712,4 @@ HWTEST_F(AbilityRecordModuleTest, Dump_001, TestSize.Level2) } } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp b/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp index 85fff73c8f3..8ed6a5f2564 100644 --- a/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp +++ b/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp @@ -97,7 +97,7 @@ void AbilityStackModuleTest::OnStartabilityMs(std::shared_ptrpendingWantManager_); int userId = abilityMs->GetUserId(); - abilityMs->SetStackManager(userId); + abilityMs->SetStackManager(userId, true); abilityMs->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs->systemAppManager_); diff --git a/services/test/moduletest/dump_module_test/dump_module_test.cpp b/services/test/moduletest/dump_module_test/dump_module_test.cpp index 96601afe88b..894ad09e12f 100644 --- a/services/test/moduletest/dump_module_test/dump_module_test.cpp +++ b/services/test/moduletest/dump_module_test/dump_module_test.cpp @@ -137,7 +137,7 @@ void DumpModuleTest::OnStartAms() EXPECT_TRUE(g_abilityMs->pendingWantManager_); int userId = g_abilityMs->GetUserId(); - g_abilityMs->SetStackManager(userId); + g_abilityMs->SetStackManager(userId, true); g_abilityMs->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(g_abilityMs->systemAppManager_); diff --git a/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp b/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp index b4732de8c88..67d8098be67 100644 --- a/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp +++ b/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp @@ -292,7 +292,7 @@ HWTEST_F(PandingWantManagerTest, pending_want_mgr_test_001, TestSize.Level1) EXPECT_NE(pandingWant, nullptr); // ams mock - EXPECT_CALL(*appClient, LoadAbility(_, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); + EXPECT_CALL(*appClient, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); std::shared_ptr callback; MockCompletedCallback *call = new MockCompletedCallback(); @@ -425,7 +425,7 @@ HWTEST_F(PandingWantManagerTest, pending_want_mgr_test_003, TestSize.Level1) EXPECT_NE(pandingWant, nullptr); // ams mock - EXPECT_CALL(*appClient, LoadAbility(_, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); + EXPECT_CALL(*appClient, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); std::shared_ptr callback; MockCompletedCallback *call = new MockCompletedCallback(); @@ -491,7 +491,7 @@ HWTEST_F(PandingWantManagerTest, pending_want_mgr_test_004, TestSize.Level1) EXPECT_NE(pandingWant, nullptr); // ams mock - EXPECT_CALL(*appClient, LoadAbility(_, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); + EXPECT_CALL(*appClient, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); std::shared_ptr callback; MockCompletedCallback *call = new MockCompletedCallback(); @@ -731,4 +731,4 @@ HWTEST_F(PandingWantManagerTest, pending_want_mgr_test_007, TestSize.Level1) EXPECT_EQ(wantAgent3->GetPendingWant()->GetTarget(), nullptr); } } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS -- Gitee From 11ad248beba9844a32ec87e0cd9a7dd28a734251 Mon Sep 17 00:00:00 2001 From: zhongjianfei Date: Wed, 12 Jan 2022 18:56:39 +0800 Subject: [PATCH 08/11] zhongjianfei@huawei.com Signed-off-by: zhongjianfei Change-Id: Id8b819381660bea94043c01df3aed00668f5de16 --- .../ability_runtime/src/connection_manager.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/frameworks/kits/ability/ability_runtime/src/connection_manager.cpp b/frameworks/kits/ability/ability_runtime/src/connection_manager.cpp index 34024efb2ee..2d832f15dd5 100755 --- a/frameworks/kits/ability/ability_runtime/src/connection_manager.cpp +++ b/frameworks/kits/ability/ability_runtime/src/connection_manager.cpp @@ -55,7 +55,7 @@ ErrCode ConnectionManager::ConnectAbility(const sptr &connectCall abilityConnection = item->first.abilityConnection; abilityConnection->SetConnectCallback(connectCallback); HILOG_INFO("%{public}s end, find abilityConnection:%{public}p exist, callbackSize:%{public}d.", - __func__, abilityConnection.GetRefPtr(), callbacks.size()); + __func__, abilityConnection.GetRefPtr(), (int32_t)callbacks.size()); if (abilityConnection->GetResultCode() == ERR_OK) { connectCallback->OnAbilityConnectDone(connectReceiver, abilityConnection->GetRemoteObject(), abilityConnection->GetResultCode()); @@ -74,7 +74,7 @@ ErrCode ConnectionManager::ConnectAbility(const sptr &connectCall abilityConnections_[connectionInfo] = callbacks; } HILOG_DEBUG("%{public}s end, not find connection, connection: %{public}p, abilityConnectionsSize:%{public}d.", - __func__, abilityConnection.GetRefPtr(), abilityConnections_.size()); + __func__, abilityConnection.GetRefPtr(), (int32_t)abilityConnections_.size()); return ret; } } @@ -100,7 +100,7 @@ ErrCode ConnectionManager::DisconnectAbility(const sptr &connectC }); if (item != abilityConnections_.end()) { std::vector> callbacks = item->second; - HILOG_DEBUG("%{public}s begin remove callback, callbackSize:%{public}d.", __func__, callbacks.size()); + HILOG_DEBUG("%{public}s begin remove callback, callbackSize:%{public}d.", __func__, (int32_t)callbacks.size()); auto iter = callbacks.begin(); while (iter != callbacks.end()) { if (*iter == connectCallback) { @@ -114,7 +114,7 @@ ErrCode ConnectionManager::DisconnectAbility(const sptr &connectC abilityConnection = item->first.abilityConnection; abilityConnection->SetConnectCallback(connectCallback); HILOG_INFO("%{public}s end, find abilityConnection:%{public}p exist, abilityConnectionsSize:%{public}d.", - __func__, abilityConnection.GetRefPtr(), abilityConnections_.size()); + __func__, abilityConnection.GetRefPtr(), (int32_t)abilityConnections_.size()); if (callbacks.size() == 0) { abilityConnections_.erase(item); HILOG_DEBUG("%{public}s disconnectAbility.", __func__); @@ -139,7 +139,7 @@ bool ConnectionManager::DisconnectCaller(const sptr &connectCalle } HILOG_DEBUG("%{public}s, connectCaller:%{public}p, abilityConnectionsSize:%{public}d.", - __func__, connectCaller.GetRefPtr(), abilityConnections_.size()); + __func__, connectCaller.GetRefPtr(), (int32_t)abilityConnections_.size()); bool isDisconnect = false; auto iter = abilityConnections_.begin(); @@ -160,14 +160,14 @@ bool ConnectionManager::DisconnectCaller(const sptr &connectCalle } } - HILOG_DEBUG("%{public}s end, abilityConnectionsSize:%{public}d.", __func__, abilityConnections_.size()); + HILOG_DEBUG("%{public}s end, abilityConnectionsSize:%{public}d.", __func__, (int32_t)abilityConnections_.size()); return isDisconnect; } bool ConnectionManager::DisconnectReceiver(const AppExecFwk::ElementName &connectReceiver) { HILOG_DEBUG("%{public}s begin, abilityConnectionsSize:%{public}d, bundleName:%{public}s, abilityName:%{public}s.", - __func__, abilityConnections_.size(), connectReceiver.GetBundleName().c_str(), + __func__, (int32_t)abilityConnections_.size(), connectReceiver.GetBundleName().c_str(), connectReceiver.GetAbilityName().c_str()); bool isDisconnect = false; @@ -182,7 +182,7 @@ bool ConnectionManager::DisconnectReceiver(const AppExecFwk::ElementName &connec } } - HILOG_DEBUG("%{public}s end, abilityConnectionsSize:%{public}d.", __func__, abilityConnections_.size()); + HILOG_DEBUG("%{public}s end, abilityConnectionsSize:%{public}d.", __func__, (int32_t)abilityConnections_.size()); return isDisconnect; } @@ -199,4 +199,4 @@ bool ConnectionManager::IsConnectReceiverEqual(const AppExecFwk::ElementName &co connectReceiver.GetAbilityName() == connectReceiverOther.GetAbilityName(); } } // namespace AbilityRuntime -} // namespace OHOS \ No newline at end of file +} // namespace OHOS -- Gitee From 0ee41350fdbe8808dc7772447c23b5b6abd6ec47 Mon Sep 17 00:00:00 2001 From: gwang Date: Wed, 12 Jan 2022 15:37:01 +0000 Subject: [PATCH 09/11] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!3?= =?UTF-8?q?21=20:=20=E6=96=B0=E5=A2=9E=E5=90=AF=E5=8A=A8&=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E5=A4=9A=E7=94=A8=E6=88=B7=E5=8A=9F=E8=83=BD'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/abilitymgr/BUILD.gn | 5 - services/abilitymgr/abilitymgr.gni | 4 - .../include/ability_manager_service.h | 22 +- services/abilitymgr/include/ability_record.h | 4 - services/abilitymgr/include/app_scheduler.h | 5 +- services/abilitymgr/include/user_controller.h | 126 ----- .../abilitymgr/include/user_event_handler.h | 52 -- .../src/ability_connect_manager.cpp | 2 +- .../src/ability_manager_service.cpp | 158 ++----- services/abilitymgr/src/ability_record.cpp | 13 +- services/abilitymgr/src/app_scheduler.cpp | 11 +- services/abilitymgr/src/user_controller.cpp | 445 ------------------ .../abilitymgr/src/user_event_handler.cpp | 42 -- services/abilitymgr/test/BUILD.gn | 7 - .../mock/include/mock_app_manager_client.h | 4 +- .../test/mock/include/mock_app_mgr_client.h | 2 +- .../include/appmgr/app_mgr_client.h | 2 +- .../src/appmgr/app_mgr_client.cpp | 2 +- .../src/appmgr/mock_app_scheduler.cpp | 3 +- .../ability_dump_test/ability_dump_test.cpp | 4 +- .../ability_manager_service_test.cpp | 4 +- .../ability_stack_manager_test.cpp | 2 +- .../ability_with_applications_test.cpp | 4 +- .../abilityms_appms_test.cpp | 4 +- .../app_scheduler_test/app_scheduler_test.cpp | 6 +- .../phone/lifecycle_test/lifecycle_test.cpp | 4 +- .../terminate_ability_test.cpp | 4 +- .../test/mock/include/mock_app_mgr_client.h | 4 +- .../ability_mgr_module_test.cpp | 61 ++- .../ability_record_module_test.cpp | 7 +- .../ability_stack_module_test.cpp | 2 +- .../dump_module_test/dump_module_test.cpp | 2 +- .../panding_want_manager_test.cpp | 8 +- 33 files changed, 97 insertions(+), 928 deletions(-) mode change 100644 => 100755 services/abilitymgr/include/ability_manager_service.h delete mode 100644 services/abilitymgr/include/user_controller.h delete mode 100644 services/abilitymgr/include/user_event_handler.h delete mode 100644 services/abilitymgr/src/user_controller.cpp delete mode 100644 services/abilitymgr/src/user_event_handler.cpp diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 2d3bd5854bd..6865fc8bc2f 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -57,10 +57,6 @@ config("abilityms_config") { "//base/global/i18n_standard/frameworks/intl/include", "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", "//base/hiviewdfx/hiview/adapter/utility/include", - "//base/account/os_account/frameworks/common/account_error/include", - "//base/account/os_account/frameworks/common/database/include", - "//base/account/os_account/frameworks/common/log/include", - "//base/account/os_account/interfaces/innerkits/osaccount/native/include", ] cflags = [] if (target_cpu == "arm") { @@ -76,7 +72,6 @@ ohos_shared_library("abilityms") { deps = [ "${innerkits_path}/base:base", "${innerkits_path}/want:want", - "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/global/i18n_standard/frameworks/intl:intl_util", "//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility", "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime:ability_context_native", diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index af51d4df38b..9f86004dab7 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -90,8 +90,4 @@ abilityms_files = [ "${services_path}/abilitymgr/src/stop_user_callback_proxy.cpp", "${services_path}/abilitymgr/src/stop_user_callback_stub.cpp", "${services_path}/abilitymgr/src/kernal_ability_manager.cpp", - - #multi user - "${services_path}/abilitymgr/src/user_controller.cpp", - "${services_path}/abilitymgr/src/user_event_handler.cpp", ] diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h old mode 100644 new mode 100755 index 082b0d62aa0..bf5bee2b625 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -42,7 +42,6 @@ #include "pending_want_manager.h" #include "ams_configuration_parameter.h" #include "event_handler.h" -#include "user_controller.h" namespace OHOS { namespace AAFwk { @@ -306,7 +305,7 @@ public: * * @param userId, user id. */ - void SetStackManager(int userId, bool switchUser); + void SetStackManager(int userId); /** * GetStackManager, get the current stack manager. @@ -581,7 +580,7 @@ public: * * @param userId, user id. */ - void InitMissionListManager(int userId, bool switchUser); + void InitMissionListManager(int userId); virtual sptr GetWantSender( const WantSenderInfo &wantSenderInfo, const sptr &callerToken) override; @@ -757,7 +756,6 @@ public: }; friend class AbilityStackManager; - friend class UserController; protected: void OnAbilityRequestDone(const sptr &token, const int32_t state) override; @@ -870,18 +868,6 @@ private: void DumpFuncInit(); bool CheckCallerIsSystemAppByIpc(); bool IsExistFile(const std::string &path); - - void InitConnectManager(int32_t userId, bool switchUser); - void InitDataAbilityManager(int32_t userId, bool switchUser); - void InitPendWantManager(int32_t userId, bool switchUser); - - // multi user - void StartFreezingScreen(); - void StopFreezingScreen(); - void UserStarted(int32_t userId); - void SwitchToUser(int32_t userId); - void StartLauncherAbility(int32_t userId); - using DumpFuncType = void (AbilityManagerService::*)(const std::string &args, std::vector &info); std::map dumpFuncMap_; @@ -893,13 +879,10 @@ private: ServiceRunningState state_; std::unordered_map> stackManagers_; std::shared_ptr currentStackManager_; - std::unordered_map> connectManagers_; std::shared_ptr connectManager_; sptr iBundleManager_; std::shared_ptr appScheduler_; - std::unordered_map> dataAbilityManagers_; std::shared_ptr dataAbilityManager_; - std::unordered_map> pendingWantManagers_; std::shared_ptr pendingWantManager_; std::shared_ptr systemAppManager_; std::shared_ptr amsConfigResolver_; @@ -913,7 +896,6 @@ private: std::shared_ptr currentMissionListManager_; std::shared_ptr kernalAbilityManager_; sptr snapshotHandler_; - std::shared_ptr userController_; }; } // namespace AAFwk diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index 5716ff2df96..985923f9794 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -117,7 +117,6 @@ struct AbilityRequest { Want want; AppExecFwk::AbilityInfo abilityInfo; AppExecFwk::ApplicationInfo appInfo; - int32_t uid = 0; int requestCode = -1; bool restart = false; sptr callerToken; @@ -734,8 +733,6 @@ public: void UpdateConfiguration(const AppExecFwk::Configuration &config) override; int GetId() override; - void SetUid(int32_t uid); - int32_t GetUid(); /** * get the type of ability. @@ -809,7 +806,6 @@ public: AppState appState_ = AppState::BEGIN; int32_t compatibleVersion_ = 0; // > 7 new version, <= 7 old version. - int32_t uid_ = 0; std::weak_ptr missionList_; std::weak_ptr mission_; int32_t missionId_ = -1; diff --git a/services/abilitymgr/include/app_scheduler.h b/services/abilitymgr/include/app_scheduler.h index 35a30294ede..10cdd498cfa 100644 --- a/services/abilitymgr/include/app_scheduler.h +++ b/services/abilitymgr/include/app_scheduler.h @@ -99,8 +99,7 @@ public: * @return true on success ,false on failure. */ int LoadAbility(const sptr &token, const sptr &preToken, - const AppExecFwk::AbilityInfo &abilityinfo, const AppExecFwk::ApplicationInfo &application, - int32_t uid); + const AppExecFwk::AbilityInfo &abilityinfo, const AppExecFwk::ApplicationInfo &application); /** * terminate ability with token. @@ -234,8 +233,6 @@ protected: virtual void OnAppStateChanged(const AppExecFwk::AppProcessData &appData) override; private: - std::recursive_mutex lock_; - bool isInit_ {false}; std::weak_ptr callback_; std::unique_ptr appMgrClient_; AppAbilityState appAbilityState_ = AppAbilityState::ABILITY_STATE_UNDEFINED; diff --git a/services/abilitymgr/include/user_controller.h b/services/abilitymgr/include/user_controller.h deleted file mode 100644 index 7fa117bcc56..00000000000 --- a/services/abilitymgr/include/user_controller.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2021 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_AAFWK_USER_CONTROLLER_H -#define OHOS_AAFWK_USER_CONTROLLER_H - -#include -#include -#include - -#include "user_event_handler.h" - -namespace OHOS { -namespace AAFwk { -const int32_t USER_ID_DEFAULT = 0; - -enum UserState { - STATE_BOOTING = 0, - STATE_STARTED, - STATE_STOPPING, - STATE_SHUTDOWN -}; - -class UserItem { -public: - explicit UserItem(int32_t id); - virtual ~UserItem(); - - int32_t GetUserId(); - void SetState(const UserState &state); - UserState GetState(); - -private: - int32_t userId_; - UserState curState_ = STATE_BOOTING; - UserState lastState_ = STATE_BOOTING; -}; - -struct UserEvent { - int32_t oldUserId; - int32_t newUserId; - std::shared_ptr userItem; -}; - -class UserController : public std::enable_shared_from_this { -public: - UserController(); - virtual ~UserController(); - - void Init(); - - /** - * Start user, if it is not running.. - * - * @param userId id of started user. - * @param isForeground whether user should brout to foreground. - * @return 0 if the user has been successfully started. - */ - int32_t StartUser(int32_t userId, bool isForeground); - - /** - * Stop user, if it is running.. - * - * @param userId id of started user. - * @return 0 if the user has been successfully started. - */ - int32_t StopUser(int32_t userId); - - int32_t GetCurrentUserId(); - - std::shared_ptr GetUserItem(int32_t userId); - - void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); - -private: - bool IsCurrentUser(int32_t userId); - bool IsExistOsAccount(int32_t userId); - std::shared_ptr GetOrCreateUserItem(int32_t userId); - void SetCurrentUserId(int32_t userId); - void BroacastUserStarted(int32_t userId); - void MoveUserToForeground(int32_t oldUserId, int32_t newUserId); - void UserBootDone(std::shared_ptr &item); - void BroacastUserBackground(int32_t userId); - void BroacastUserForeground(int32_t userId); - - void SendSystemUserStart(int32_t userId); - void SendSystemUserCurrent(int32_t oldUserId, int32_t newUserId); - void SendReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void SendUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void SendContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void SendUserSwitchDone(int32_t userId); - - void HandleSystemUserStart(int32_t userId); - void HandleSystemUserCurrent(int32_t oldUserId, int32_t newUserId); - void HandleReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void HandleUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void HandleContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem); - void HandleUserSwitchDone(int32_t userId); - -private: - std::recursive_mutex userLock_; - int32_t currentUserId_ = USER_ID_DEFAULT; - std::unordered_map> userItems_; - std::shared_ptr eventHandler_; -}; -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_AAFWK_USER_CONTROLLER_H \ No newline at end of file diff --git a/services/abilitymgr/include/user_event_handler.h b/services/abilitymgr/include/user_event_handler.h deleted file mode 100644 index ad22a2dcc5d..00000000000 --- a/services/abilitymgr/include/user_event_handler.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2021 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_AAFWK_USER_EVENT_HANDLER_H -#define OHOS_AAFWK_USER_EVENT_HANDLER_H - -#include - -#include "event_handler.h" -#include "event_runner.h" - -namespace OHOS { -namespace AAFwk { -class UserController; -class UserEventHandler : public AppExecFwk::EventHandler { -public: - UserEventHandler( - const std::shared_ptr &runner, const std::weak_ptr &owner); - virtual ~UserEventHandler() = default; - - static constexpr uint32_t EVENT_SYSTEM_USER_START = 10; - static constexpr uint32_t EVENT_SYSTEM_USER_CURRENT = 20; - static constexpr uint32_t EVENT_REPORT_USER_SWITCH = 30; - static constexpr uint32_t EVENT_CONTINUE_USER_SWITCH = 40; - static constexpr uint32_t EVENT_USER_SWITCH_TIMEOUT = 50; - static constexpr uint32_t EVENT_REPORT_USER_SWITCH_DONE = 60; - - /** - * ProcessEvent with request. - * - * @param event, inner event loop. - */ - void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; - -private: - std::weak_ptr controller_; -}; -} // namespace AAFwk -} // namespace OHOS -#endif // OHOS_AAFWK_USER_EVENT_HANDLER_H \ No newline at end of file diff --git a/services/abilitymgr/src/ability_connect_manager.cpp b/services/abilitymgr/src/ability_connect_manager.cpp index 3354409b9ef..7ef5c48e229 100755 --- a/services/abilitymgr/src/ability_connect_manager.cpp +++ b/services/abilitymgr/src/ability_connect_manager.cpp @@ -577,7 +577,7 @@ void AbilityConnectManager::LoadAbility(const std::shared_ptr &ab } } DelayedSingleton::GetInstance()->LoadAbility( - token, perToken, abilityRecord->GetAbilityInfo(), abilityRecord->GetApplicationInfo(), abilityRecord->GetUid()); + token, perToken, abilityRecord->GetAbilityInfo(), abilityRecord->GetApplicationInfo()); abilityRecord->SetStartTime(); } diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 1ea285e799a..016320bfe55 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -89,6 +89,7 @@ AbilityManagerService::AbilityManagerService() eventLoop_(nullptr), handler_(nullptr), state_(ServiceRunningState::STATE_NOT_START), + connectManager_(std::make_shared()), iBundleManager_(nullptr) { std::shared_ptr appScheduler( @@ -131,19 +132,14 @@ bool AbilityManagerService::Init() handler_ = std::make_shared(eventLoop_, weak_from_this()); CHECK_POINTER_RETURN_BOOL(handler_); - - // init user controller. - userController_ = std::make_shared(); - userController_->Init(); - int userId = GetUserId(); - - InitConnectManager(userId, true); + CHECK_POINTER_RETURN_BOOL(connectManager_); + connectManager_->SetEventHandler(handler_); // init ConfigurationDistributor DelayedSingleton::GetInstance(); - InitDataAbilityManager(userId, true); - InitPendWantManager(userId, true); + auto dataAbilityManager = std::make_shared(); + CHECK_POINTER_RETURN_BOOL(dataAbilityManager); amsConfigResolver_ = std::make_shared(); if (amsConfigResolver_) { @@ -152,15 +148,22 @@ bool AbilityManagerService::Init() } useNewMission_ = amsConfigResolver_->IsUseNewMission(); + auto pendingWantManager = std::make_shared(); + if (!pendingWantManager) { + HILOG_ERROR("Failed to init pending want ability manager."); + return false; + } + // after amsConfigResolver_ configuration_ = std::make_shared(); GetGlobalConfiguration(); - SetStackManager(userId, true); + int userId = GetUserId(); + SetStackManager(userId); systemAppManager_ = std::make_shared(userId); CHECK_POINTER_RETURN_BOOL(systemAppManager_); - InitMissionListManager(userId, true); + InitMissionListManager(userId); kernalAbilityManager_ = std::make_shared(userId); CHECK_POINTER_RETURN_BOOL(kernalAbilityManager_); @@ -182,6 +185,8 @@ bool AbilityManagerService::Init() outFile.close(); }; handler_->PostTask(creatWhiteListTask, "creatWhiteList"); + dataAbilityManager_ = dataAbilityManager; + pendingWantManager_ = pendingWantManager; HILOG_INFO("Init success."); return true; } @@ -1836,37 +1841,27 @@ std::shared_ptr AbilityManagerService::GetEventHandler() return handler_; } -void AbilityManagerService::SetStackManager(int userId, bool switchUser) +void AbilityManagerService::SetStackManager(int userId) { auto iterator = stackManagers_.find(userId); if (iterator != stackManagers_.end()) { - if (switchUser) { - currentStackManager_ = iterator->second; - } + currentStackManager_ = iterator->second; } else { - auto manager = std::make_shared(userId); - manager->Init(); - stackManagers_.emplace(userId, manager); - if (switchUser) { - currentStackManager_ = manager; - } + currentStackManager_ = std::make_shared(userId); + currentStackManager_->Init(); + stackManagers_.emplace(userId, currentStackManager_); } } -void AbilityManagerService::InitMissionListManager(int userId, bool switchUser) +void AbilityManagerService::InitMissionListManager(int userId) { auto iterator = missionListManagers_.find(userId); if (iterator != missionListManagers_.end()) { - if (switchUser) { - currentMissionListManager_ = iterator->second; - } + currentMissionListManager_ = iterator->second; } else { - auto manager = std::make_shared(userId); - manager->Init(); - missionListManagers_.emplace(userId, manager); - if (switchUser) { - currentMissionListManager_ = manager; - } + currentMissionListManager_ = std::make_shared(userId); + currentMissionListManager_->Init(); + missionListManagers_.emplace(userId, currentMissionListManager_); } } @@ -1884,9 +1879,6 @@ void AbilityManagerService::DumpWaittingAbilityQueue(std::string &result) // multi user scene int AbilityManagerService::GetUserId() { - if (userController_) { - return userController_->GetCurrentUserId(); - } return DEFAULT_USER_ID; } @@ -1997,9 +1989,7 @@ int AbilityManagerService::GenerateAbilityRequest( auto bms = GetBundleManager(); CHECK_POINTER_AND_RETURN(bms, GET_ABILITY_SERVICE_FAILED); - int userId = GetUserId(); - bms->QueryAbilityInfo(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, - userId, request.abilityInfo); + bms->QueryAbilityInfo(want, AppExecFwk::AbilityInfoFlag::GET_ABILITY_INFO_WITH_APPLICATION, 0, request.abilityInfo); if (request.abilityInfo.name.empty() || request.abilityInfo.bundleName.empty()) { HILOG_ERROR("Get ability info failed."); return RESOLVE_ABILITY_ERR; @@ -2028,13 +2018,11 @@ int AbilityManagerService::GenerateAbilityRequest( HILOG_DEBUG("Query app name: %{public}s,", request.appInfo.name.c_str()); AppExecFwk::BundleInfo bundleInfo; - if (!bms->GetBundleInfo(request.appInfo.bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, - bundleInfo, userId)) { + if (!bms->GetBundleInfo(request.appInfo.bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo)) { HILOG_ERROR("Failed to get bundle info when generate ability request."); return RESOLVE_APP_ERR; } request.compatibleVersion = bundleInfo.compatibleVersion; - request.uid = bundleInfo.uid; return ERR_OK; } @@ -2207,8 +2195,7 @@ int AbilityManagerService::PreLoadAppDataAbilities(const std::string &bundleName CHECK_POINTER_AND_RETURN(bms, GET_ABILITY_SERVICE_FAILED); AppExecFwk::BundleInfo bundleInfo; - int32_t userId = GetUserId(); - bool ret = bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo, userId); + bool ret = bms->GetBundleInfo(bundleName, AppExecFwk::BundleFlag::GET_BUNDLE_WITH_ABILITIES, bundleInfo); if (!ret) { HILOG_ERROR("Failed to get bundle info when app data abilities preloading."); return RESOLVE_APP_ERR; @@ -2228,7 +2215,6 @@ int AbilityManagerService::PreLoadAppDataAbilities(const std::string &bundleName return ERR_TIMED_OUT; } dataAbilityRequest.abilityInfo = *it; - dataAbilityRequest.uid = bundleInfo.uid; HILOG_INFO("App data ability preloading: '%{public}s.%{public}s'...", it->bundleName.c_str(), it->name.c_str()); auto dataAbility = dataAbilityManager_->Acquire(dataAbilityRequest, false, nullptr, false); @@ -2809,91 +2795,5 @@ int32_t AbilityManagerService::GetMissionSnapshot(const std::string& deviceId, i missionSnapshot.snapshot = snapshot.GetPixelMap(); return result; } - -void AbilityManagerService::StartFreezingScreen() -{ - HILOG_DEBUG("%{public}s", __func__); -} - -void AbilityManagerService::StopFreezingScreen() -{ - HILOG_DEBUG("%{public}s", __func__); -} - -void AbilityManagerService::UserStarted(int32_t userId) -{ - HILOG_DEBUG("%{public}s", __func__); - InitConnectManager(userId, false); - SetStackManager(userId, false); - InitMissionListManager(userId, false); - InitDataAbilityManager(userId, false); - InitPendWantManager(userId, false); -} - -void AbilityManagerService::SwitchToUser(int32_t userId) -{ - HILOG_DEBUG("%{public}s", __func__); - InitConnectManager(userId, true); - SetStackManager(userId, true); - InitMissionListManager(userId, true); - InitDataAbilityManager(userId, true); - InitPendWantManager(userId, true); -} - -void AbilityManagerService::StartLauncherAbility(int32_t userId) -{ - HILOG_DEBUG("StartLauncherAbility, userId:%{public}d, currentUserId:%{public}d", userId, GetUserId()); - ConnectBmsService(); - StartingLauncherAbility(); -} - -void AbilityManagerService::InitConnectManager(int32_t userId, bool switchUser) -{ - auto it = connectManagers_.find(userId); - if (it == connectManagers_.end()) { - auto manager = std::make_shared(); - manager->SetEventHandler(handler_); - connectManagers_.emplace(userId, manager); - if (switchUser) { - connectManager_ = manager; - } - } else { - if (switchUser) { - connectManager_ = it->second; - } - } -} - -void AbilityManagerService::InitDataAbilityManager(int32_t userId, bool switchUser) -{ - auto it = dataAbilityManagers_.find(userId); - if (it == dataAbilityManagers_.end()) { - auto manager = std::make_shared(); - dataAbilityManagers_.emplace(userId, manager); - if (switchUser) { - dataAbilityManager_ = manager; - } - } else { - if (switchUser) { - dataAbilityManager_ = it->second; - } - } -} - -void AbilityManagerService::InitPendWantManager(int32_t userId, bool switchUser) -{ - auto it = pendingWantManagers_.find(userId); - if (it == pendingWantManagers_.end()) { - auto manager = std::make_shared(); - pendingWantManagers_.emplace(userId, manager); - if (switchUser) { - pendingWantManager_ = manager; - } - } else { - if (switchUser) { - pendingWantManager_ = it->second; - } - } -} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index aa3abd3f8c9..31b20b5d720 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -111,7 +111,6 @@ std::shared_ptr AbilityRecord::CreateAbilityRecord(const AbilityR abilityRequest.appInfo, abilityRequest.requestCode, abilityRequest.compatibleVersion); } CHECK_POINTER_AND_RETURN(abilityRecord, nullptr); - abilityRecord->SetUid(abilityRequest.uid); if (!abilityRecord->Init()) { HILOG_ERROR("failed to init new ability record"); return nullptr; @@ -137,16 +136,6 @@ bool AbilityRecord::Init() return true; } -void AbilityRecord::SetUid(int32_t uid) -{ - uid_ = uid; -} - -int32_t AbilityRecord::GetUid() -{ - return uid_; -} - int AbilityRecord::LoadAbility() { BYTRACE_NAME(BYTRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); @@ -171,7 +160,7 @@ int AbilityRecord::LoadAbility() callerToken_ = callerList_.back()->GetCaller()->GetToken(); } return DelayedSingleton::GetInstance()->LoadAbility( - token_, callerToken_, abilityInfo_, applicationInfo_, uid_); + token_, callerToken_, abilityInfo_, applicationInfo_); } void AbilityRecord::ForegroundAbility() diff --git a/services/abilitymgr/src/app_scheduler.cpp b/services/abilitymgr/src/app_scheduler.cpp index 5a09640484d..7a6b868ad66 100644 --- a/services/abilitymgr/src/app_scheduler.cpp +++ b/services/abilitymgr/src/app_scheduler.cpp @@ -35,11 +35,6 @@ bool AppScheduler::Init(const std::weak_ptr &callback) CHECK_POINTER_RETURN_BOOL(callback.lock()); CHECK_POINTER_RETURN_BOOL(appMgrClient_); - std::lock_guard guard(lock_); - if (isInit_) { - return true; - } - callback_ = callback; /* because the errcode type of AppMgr Client API will be changed to int, * so must to covert the return result */ @@ -55,19 +50,17 @@ bool AppScheduler::Init(const std::weak_ptr &callback) return false; } HILOG_INFO("success to ConnectAppMgrService"); - isInit_ = true; return true; } int AppScheduler::LoadAbility(const sptr &token, const sptr &preToken, - const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo, - int32_t uid) + const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo) { HILOG_DEBUG("Load ability."); CHECK_POINTER_AND_RETURN(appMgrClient_, INNER_ERR); /* because the errcode type of AppMgr Client API will be changed to int, * so must to covert the return result */ - int ret = static_cast(appMgrClient_->LoadAbility(token, preToken, abilityInfo, applicationInfo, uid)); + int ret = static_cast(appMgrClient_->LoadAbility(token, preToken, abilityInfo, applicationInfo)); if (ret != ERR_OK) { HILOG_ERROR("AppScheduler fail to LoadAbility. ret %d", ret); return INNER_ERR; diff --git a/services/abilitymgr/src/user_controller.cpp b/services/abilitymgr/src/user_controller.cpp deleted file mode 100644 index 8fe353d91b2..00000000000 --- a/services/abilitymgr/src/user_controller.cpp +++ /dev/null @@ -1,445 +0,0 @@ -/* - * Copyright (c) 2021 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 "user_controller.h" - -#include "ability_manager_service.h" -#include "hilog_wrapper.h" -#include "ipc_skeleton.h" -#include "os_account_manager.h" - -namespace OHOS { -namespace AAFwk { -using namespace OHOS::AppExecFwk; -namespace { -const int64_t USER_SWITCH_TIMEOUT = 3 * 1000; // 3s - -class Holder { -public: - Holder() - { - identity_ = IPCSkeleton::ResetCallingIdentity(); - } - - ~Holder() - { - IPCSkeleton::SetCallingIdentity(identity_); - } - -private: - std::string identity_; -}; -} - -UserItem::UserItem(int32_t id) : userId_(id) -{} - -UserItem::~UserItem() {} - -int32_t UserItem::GetUserId() -{ - return userId_; -} - -void UserItem::SetState(const UserState &state) -{ - if (curState_ == state) { - return; - } - lastState_ = curState_; - curState_ = state; -} - -UserState UserItem::GetState() -{ - return curState_; -} - -UserController::UserController() -{ -} - -UserController::~UserController() -{ -} - -void UserController::Init() -{ - auto handler = DelayedSingleton::GetInstance()->GetEventHandler(); - if (!handler) { - return; - } - - auto runner = handler->GetEventRunner(); - if (!runner) { - return; - } - - if (eventHandler_) { - return; - } - eventHandler_ = std::make_shared(runner, shared_from_this()); -} - -int32_t UserController::StartUser(int32_t userId, bool isForeground) -{ - if (userId < 0 || userId == USER_ID_DEFAULT) { - HILOG_ERROR("StartUser userId is invalid:%{public}d", userId); - return -1; - } - - if (IsCurrentUser(userId)) { - HILOG_WARN("StartUser user is already current:%{public}d", userId); - return 0; - } - - if (!IsExistOsAccount(userId)) { - HILOG_ERROR("StartUser not exist such account:%{public}d", userId); - return -1; - } - - if (isForeground) { - // start freezing screen - DelayedSingleton::GetInstance()->StartFreezingScreen(); - } - - auto oldUserId = GetCurrentUserId(); - auto userItem = GetOrCreateUserItem(userId); - auto state = userItem->GetState(); - if (state == STATE_STOPPING || state == STATE_SHUTDOWN) { - HILOG_ERROR("StartUser user is stop now, userId:%{public}d", userId); - return -1; - } - - if (isForeground) { - SetCurrentUserId(userId); - // todo : notify wms switching now - } - - bool needStart = false; - if (state == STATE_BOOTING) { - needStart = true; - // send user start msg. - SendSystemUserStart(userId); - } - - if (isForeground) { - SendSystemUserCurrent(oldUserId, userId); - SendReportUserSwitch(oldUserId, userId, userItem); - SendUserSwitchTimeout(oldUserId, userId, userItem); - } - - if (needStart) { - BroacastUserStarted(userId); - } - - UserBootDone(userItem); - if (isForeground) { - MoveUserToForeground(oldUserId, userId); - } - - return 0; -} - -int32_t UserController::StopUser(int32_t userId) -{ - return -1; -} - -int32_t UserController::GetCurrentUserId() -{ - std::lock_guard guard(userLock_); - return currentUserId_; -} - -std::shared_ptr UserController::GetUserItem(int32_t userId) -{ - std::lock_guard guard(userLock_); - auto it = userItems_.find(userId); - if (it != userItems_.end()) { - return it->second; - } - - return nullptr; -} - -bool UserController::IsCurrentUser(int32_t userId) -{ - int32_t oldUserId = GetCurrentUserId(); - if (oldUserId == userId) { - auto userItem = GetUserItem(userId); - if (userItem) { - HILOG_WARN("IsCurrentUser userId is already current:%{public}d", userId); - return true; - } - } - return false; -} - -bool UserController::IsExistOsAccount(int32_t userId) -{ - bool isExist = false; - auto errCode = AccountSA::OsAccountManager::IsOsAccountExists(userId, isExist); - return (errCode == 0) && isExist; -} - -std::shared_ptr UserController::GetOrCreateUserItem(int32_t userId) -{ - std::lock_guard guard(userLock_); - auto it = userItems_.find(userId); - if (it != userItems_.end()) { - return it->second; - } - - auto userItem = std::make_shared(userId); - userItems_.emplace(userId, userItem); - return userItem; -} - -void UserController::SetCurrentUserId(int32_t userId) -{ - std::lock_guard guard(userLock_); - currentUserId_ = userId; -} - -void UserController::MoveUserToForeground(int32_t oldUserId, int32_t newUserId) -{ - auto ams = DelayedSingleton::GetInstance(); - if (!ams) { - return; - } - ams->SwitchToUser(newUserId); - ams->StartLauncherAbility(newUserId); - BroacastUserBackground(oldUserId); - BroacastUserForeground(newUserId); -} - -void UserController::UserBootDone(std::shared_ptr &item) -{ - if (!item) { - return; - } - int32_t userId = item->GetUserId(); - - std::lock_guard guard(userLock_); - auto it = userItems_.find(userId); - if (it != userItems_.end()) { - return; - } - - if (item != it->second) { - return; - } - item->SetState(UserState::STATE_STARTED); - auto ams = DelayedSingleton::GetInstance(); - if (!ams) { - return; - } - ams->UserStarted(userId); -} - -void UserController::BroacastUserStarted(int32_t userId) -{ - // todo: broadcast event user start. -} - -void UserController::BroacastUserBackground(int32_t userId) -{ - // todo: broadcast event user switch to bg. -} - -void UserController::BroacastUserForeground(int32_t userId) -{ - // todo: broadcast event user switch to fg. -} - -void UserController::SendSystemUserStart(int32_t userId) -{ - auto handler = eventHandler_; - if (!handler) { - return; - } - - std::shared_ptr eventData = std::make_shared(); - eventData->newUserId = userId; - auto event = InnerEvent::Get(UserEventHandler::EVENT_SYSTEM_USER_START, eventData); - handler->SendEvent(event); -} - -void UserController::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) -{ - if (!event) { - return; - } - - auto eventId = event->GetInnerEventId(); - auto eventData = event->GetSharedObject(); - if (!eventData) { - HILOG_DEBUG("no event data, event id: %{public}u.", eventId); - return; - } - - HILOG_DEBUG("Event id obtained: %{public}u.", eventId); - switch (eventId) { - case UserEventHandler::EVENT_SYSTEM_USER_START: { - HandleSystemUserStart(eventData->newUserId); - break; - } - case UserEventHandler::EVENT_SYSTEM_USER_CURRENT: { - HandleSystemUserCurrent(eventData->oldUserId, eventData->newUserId); - break; - } - case UserEventHandler::EVENT_REPORT_USER_SWITCH: { - HandleReportUserSwitch(eventData->oldUserId, eventData->newUserId, eventData->userItem); - break; - } - case UserEventHandler::EVENT_CONTINUE_USER_SWITCH: { - HandleContinueUserSwitch(eventData->oldUserId, eventData->newUserId, eventData->userItem); - break; - } - case UserEventHandler::EVENT_USER_SWITCH_TIMEOUT: { - HandleUserSwitchTimeout(eventData->oldUserId, eventData->newUserId, eventData->userItem); - break; - } - case UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE: { - HandleUserSwitchDone(eventData->newUserId); - break; - } - default: { - HILOG_WARN("Unsupported event."); - break; - } - } -} - -void UserController::SendSystemUserCurrent(int32_t oldUserId, int32_t newUserId) -{ - auto handler = eventHandler_; - if (!handler) { - return; - } - - std::shared_ptr eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - auto event = InnerEvent::Get(UserEventHandler::EVENT_SYSTEM_USER_CURRENT, eventData); - handler->SendEvent(event); -} - -void UserController::SendReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto handler = eventHandler_; - if (!handler) { - return; - } - - handler->RemoveEvent(UserEventHandler::EVENT_REPORT_USER_SWITCH); - std::shared_ptr eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - eventData->userItem = usrItem; - auto event = InnerEvent::Get(UserEventHandler::EVENT_REPORT_USER_SWITCH, eventData); - handler->SendEvent(event); -} - -void UserController::SendUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto handler = eventHandler_; - if (!handler) { - return; - } - - handler->RemoveEvent(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT); - std::shared_ptr eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - eventData->userItem = usrItem; - auto event = InnerEvent::Get(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT, eventData); - handler->SendEvent(event, USER_SWITCH_TIMEOUT); -} - -void UserController::SendContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto handler = eventHandler_; - if (!handler) { - return; - } - - handler->RemoveEvent(UserEventHandler::EVENT_USER_SWITCH_TIMEOUT); - std::shared_ptr eventData = std::make_shared(); - eventData->oldUserId = oldUserId; - eventData->newUserId = newUserId; - eventData->userItem = usrItem; - auto event = InnerEvent::Get(UserEventHandler::EVENT_CONTINUE_USER_SWITCH, eventData); - handler->SendEvent(event); -} - -void UserController::SendUserSwitchDone(int32_t userId) -{ - auto handler = eventHandler_; - if (!handler) { - return; - } - - handler->RemoveEvent(UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE); - std::shared_ptr eventData = std::make_shared(); - eventData->newUserId = userId; - auto event = InnerEvent::Get(UserEventHandler::EVENT_REPORT_USER_SWITCH_DONE, eventData); - handler->SendEvent(event); -} - -void UserController::HandleSystemUserStart(int32_t userId) -{ - // todo : notify system mgr user start. -} - -void UserController::HandleSystemUserCurrent(int32_t oldUserId, int32_t newUserId) -{ - // todo : notify system mgr user switch to new. -} - -void UserController::HandleReportUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - // todo : notify user switch observers, not support yet. -} - -void UserController::HandleUserSwitchTimeout(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - // todo : other observers - SendContinueUserSwitch(oldUserId, newUserId, usrItem); -} - -void UserController::HandleContinueUserSwitch(int32_t oldUserId, int32_t newUserId, - std::shared_ptr &usrItem) -{ - auto ams = DelayedSingleton::GetInstance(); - if (ams) { - ams->StopFreezingScreen(); - } - SendUserSwitchDone(newUserId); -} - -void UserController::HandleUserSwitchDone(int32_t userId) -{ - // todo : notify wms switching done. - // todo : notify user switch observers. -} -} -} diff --git a/services/abilitymgr/src/user_event_handler.cpp b/services/abilitymgr/src/user_event_handler.cpp deleted file mode 100644 index c701713518f..00000000000 --- a/services/abilitymgr/src/user_event_handler.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2021 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 "user_event_handler.h" - -#include "user_controller.h" -#include "hilog_wrapper.h" - -namespace OHOS { -namespace AAFwk { -UserEventHandler::UserEventHandler( - const std::shared_ptr &runner, const std::weak_ptr &owner) - : AppExecFwk::EventHandler(runner), controller_(owner) -{ -} - -void UserEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) -{ - if (!event) { - HILOG_ERROR("invalid event"); - return; - } - - auto owner = controller_.lock(); - if (owner) { - owner->ProcessEvent(event); - } -} -} // namespace AAFwk -} // namespace OHOS diff --git a/services/abilitymgr/test/BUILD.gn b/services/abilitymgr/test/BUILD.gn index a782a35ef33..46829a95314 100644 --- a/services/abilitymgr/test/BUILD.gn +++ b/services/abilitymgr/test/BUILD.gn @@ -82,8 +82,6 @@ ohos_source_set("abilityms_test_source") { "${services_path}/abilitymgr/src/stack_info.cpp", "${services_path}/abilitymgr/src/stack_setting.cpp", "${services_path}/abilitymgr/src/task_data_persistence_mgr.cpp", - "${services_path}/abilitymgr/src/user_controller.cpp", - "${services_path}/abilitymgr/src/user_event_handler.cpp", "${services_path}/abilitymgr/src/want_receiver_proxy.cpp", "${services_path}/abilitymgr/src/want_receiver_stub.cpp", "${services_path}/abilitymgr/src/want_sender_info.cpp", @@ -101,10 +99,6 @@ ohos_source_set("abilityms_test_source") { "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy/include", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core/include/appmgr", "//foundation/aafwk/standard/interfaces/innerkits/dataobs_manager/include", - "//base/account/os_account/frameworks/common/account_error/include", - "//base/account/os_account/frameworks/common/database/include", - "//base/account/os_account/frameworks/common/log/include", - "//base/account/os_account/interfaces/innerkits/osaccount/native/include", ] external_dependent_files = [ @@ -128,7 +122,6 @@ ohos_source_set("abilityms_test_source") { "${innerkits_path}/base:base", "${innerkits_path}/want:want", "${services_path}/abilitymgr/test/mock/libs/sa_mgr:sa_mgr_mock", - "//base/account/os_account/frameworks/osaccount/native:os_account_innerkits", "//base/global/i18n_standard/frameworks/intl:intl_util", "//base/hiviewdfx/hiview/adapter/utility:hiview_adapter_utility", "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base:appexecfwk_base", diff --git a/services/abilitymgr/test/mock/include/mock_app_manager_client.h b/services/abilitymgr/test/mock/include/mock_app_manager_client.h index 3a1d2a59b45..b05c3802034 100644 --- a/services/abilitymgr/test/mock/include/mock_app_manager_client.h +++ b/services/abilitymgr/test/mock/include/mock_app_manager_client.h @@ -28,8 +28,8 @@ public: {} ~MockAppMgrClient() {} - MOCK_METHOD5(LoadAbility, AppMgrResultCode(const sptr &token, const sptr &preToken, - const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo, int32_t uid)); + MOCK_METHOD4(LoadAbility, AppMgrResultCode(const sptr &token, const sptr &preToken, + const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo)); MOCK_METHOD1(TerminateAbility, AppMgrResultCode(const sptr &)); MOCK_METHOD2(UpdateAbilityState, AppMgrResultCode(const sptr &token, const AbilityState state)); diff --git a/services/abilitymgr/test/mock/include/mock_app_mgr_client.h b/services/abilitymgr/test/mock/include/mock_app_mgr_client.h index 1c1ba629bc1..102804069df 100644 --- a/services/abilitymgr/test/mock/include/mock_app_mgr_client.h +++ b/services/abilitymgr/test/mock/include/mock_app_mgr_client.h @@ -29,7 +29,7 @@ public: virtual ~MockAppMgrClient() {}; virtual AppMgrResultCode LoadAbility(const sptr &token, const sptr &preToken, - const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo, int32_t uid) + const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo) { HILOG_INFO("MockAppMgrClient LoadAbility enter."); token_ = token; diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h index 71ac01703ba..2688800e3b0 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/include/appmgr/app_mgr_client.h @@ -42,7 +42,7 @@ public: * @return Returns RESULT_OK on success, others on failure. */ virtual AppMgrResultCode LoadAbility(const sptr &token, const sptr &preToken, - const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo, int32_t uid); + const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo); /** * Terminate ability. diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp index 657293e5a89..6fc4637e106 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/app_mgr_client.cpp @@ -35,7 +35,7 @@ AppMgrClient::~AppMgrClient() {} AppMgrResultCode AppMgrClient::LoadAbility(const sptr &token, const sptr &preToken, - const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo, int32_t uid) + const AbilityInfo &abilityInfo, const ApplicationInfo &appInfo) { return AppMgrResultCode::RESULT_OK; } diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp index fa0f4328e76..596295ec13f 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp @@ -43,8 +43,7 @@ bool AppScheduler::Init(const std::weak_ptr &callback) } int AppScheduler::LoadAbility(const sptr &token, const sptr &preToken, - const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo, - int32_t uid) + const AppExecFwk::AbilityInfo &abilityInfo, const AppExecFwk::ApplicationInfo &applicationInfo) { HILOG_INFO("Test AppScheduler::LoadAbility()"); if (applicationInfo.bundleName.find("com.ix.First.Test") != std::string::npos) { diff --git a/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp b/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp index e44e936e867..e711dfd8d7b 100644 --- a/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_dump_test/ability_dump_test.cpp @@ -141,7 +141,7 @@ void AbilityDumpTest::OnStartAms() EXPECT_TRUE(g_abilityMs->pendingWantManager_); int userId = g_abilityMs->GetUserId(); - g_abilityMs->SetStackManager(userId, true); + g_abilityMs->SetStackManager(userId); g_abilityMs->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(g_abilityMs->systemAppManager_); @@ -558,4 +558,4 @@ HWTEST_F(AbilityDumpTest, Ability_Dump_013, TestSize.Level2) GTEST_LOG_(INFO) << "Ability_Dump_013 end"; } } // namespace AAFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp index 1bea8f98ddf..d85093bf6fc 100755 --- a/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_manager_service_test/ability_manager_service_test.cpp @@ -147,7 +147,7 @@ void AbilityManagerServiceTest::OnStartAms() abilityMs_->GetGlobalConfiguration(); int userId = abilityMs_->GetUserId(); - abilityMs_->SetStackManager(userId, true); + abilityMs_->SetStackManager(userId); abilityMs_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs_->systemAppManager_); @@ -615,7 +615,7 @@ HWTEST_F(AbilityManagerServiceTest, Interface_012, TestSize.Level1) */ HWTEST_F(AbilityManagerServiceTest, Interface_013, TestSize.Level1) { - abilityMs_->SetStackManager(0, true); + abilityMs_->SetStackManager(0); EXPECT_NE(nullptr, abilityMs_->GetStackManager()); } diff --git a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp index 81a9e356636..7c8547bc4e8 100644 --- a/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_stack_manager_test/ability_stack_manager_test.cpp @@ -100,7 +100,7 @@ void AbilityStackManagerTest::OnStartabilityMs() EXPECT_TRUE(abilityMs_->pendingWantManager_); int userId = abilityMs_->GetUserId(); - abilityMs_->SetStackManager(userId, true); + abilityMs_->SetStackManager(userId); abilityMs_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs_->systemAppManager_); diff --git a/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp b/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp index 25ccafc9ab1..d59933c3acc 100644 --- a/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp +++ b/services/abilitymgr/test/unittest/phone/ability_with_applications_test/ability_with_applications_test.cpp @@ -110,7 +110,7 @@ void AbilityWithApplicationsTest::OnStartabilityAms() EXPECT_TRUE(abilityMs_->pendingWantManager_); int userId = abilityMs_->GetUserId(); - abilityMs_->SetStackManager(userId, true); + abilityMs_->SetStackManager(userId); abilityMs_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs_->systemAppManager_); @@ -380,4 +380,4 @@ HWTEST_F(AbilityWithApplicationsTest, Teminate_Ability_With_Applications_002, Te GTEST_LOG_(INFO) << "Teminate_Ability_With_Applications_002 end"; } } // namespace AAFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp b/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp index 228314d13d0..b3214d77cbf 100644 --- a/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp +++ b/services/abilitymgr/test/unittest/phone/abilityms_appms_test/abilityms_appms_test.cpp @@ -119,7 +119,7 @@ void AbilityMsAppmsTest::OnStartabilityAms() EXPECT_TRUE(abilityMs_->pendingWantManager_); int userId = abilityMs_->GetUserId(); - abilityMs_->SetStackManager(userId, true); + abilityMs_->SetStackManager(userId); abilityMs_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs_->systemAppManager_); @@ -324,4 +324,4 @@ HWTEST_F(AbilityMsAppmsTest, AaFwk_AbilityMS_AppMS_005, TestSize.Level1) GTEST_LOG_(INFO) << "AbilityMsAppMsTest_AaFwk_AbilityMS_AppMS_005 end"; } } // namespace AAFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/test/unittest/phone/app_scheduler_test/app_scheduler_test.cpp b/services/abilitymgr/test/unittest/phone/app_scheduler_test/app_scheduler_test.cpp index 724f6f6446f..01ce6281628 100644 --- a/services/abilitymgr/test/unittest/phone/app_scheduler_test/app_scheduler_test.cpp +++ b/services/abilitymgr/test/unittest/phone/app_scheduler_test/app_scheduler_test.cpp @@ -128,7 +128,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_oprator_003, TestSize.Level1) EXPECT_EQ((int)ERR_OK, DelayedSingleton::GetInstance()->LoadAbility( - token, pretoken, record->GetAbilityInfo(), record->GetApplicationInfo(), 0)); + token, pretoken, record->GetAbilityInfo(), record->GetApplicationInfo())); } /* @@ -159,7 +159,7 @@ HWTEST_F(AppSchedulerTest, AppScheduler_oprator_004, TestSize.Level1) DelayedSingleton::GetInstance()->appMgrClient_ = nullptr; EXPECT_NE((int)ERR_OK, DelayedSingleton::GetInstance()->LoadAbility( - token, pretoken, record->GetAbilityInfo(), record->GetApplicationInfo(), 0)); + token, pretoken, record->GetAbilityInfo(), record->GetApplicationInfo())); } /* @@ -465,4 +465,4 @@ HWTEST_F(AppSchedulerTest, AppScheduler_oprator_017, TestSize.Level1) DelayedSingleton::GetInstance()->KillProcessByAbilityToken(token); } } // namespace AAFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp b/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp index 229040dfdf7..d516a84db4d 100644 --- a/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp +++ b/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp @@ -119,7 +119,7 @@ void LifecycleTest::OnStartabilityAms() EXPECT_TRUE(abilityMs_->pendingWantManager_); int userId = abilityMs_->GetUserId(); - abilityMs_->SetStackManager(userId, true); + abilityMs_->SetStackManager(userId); abilityMs_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs_->systemAppManager_); @@ -630,4 +630,4 @@ HWTEST_F(LifecycleTest, AAFWK_AbilityMS_startAbilityLifeCycle_007, TestSize.Leve } } } // namespace AAFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp b/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp index fcc6f63efa8..c03c2818c39 100644 --- a/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp +++ b/services/abilitymgr/test/unittest/phone/terminate_ability_test/terminate_ability_test.cpp @@ -153,7 +153,7 @@ void TerminateAbilityTest::OnStartAms() EXPECT_TRUE(g_aams->pendingWantManager_); int userId = g_aams->GetUserId(); - g_aams->SetStackManager(userId, true); + g_aams->SetStackManager(userId); g_aams->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(g_aams->systemAppManager_); @@ -784,4 +784,4 @@ HWTEST_F(TerminateAbilityTest, AAFWK_g_aamsTerminateAbility_014, TestSize.Level1 EXPECT_EQ(g_aams->TerminateAbility(token, -1, nullptr), 0); } } // namespace AAFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/test/mock/include/mock_app_mgr_client.h b/services/test/mock/include/mock_app_mgr_client.h index b005e7f5dac..47aefe463a8 100644 --- a/services/test/mock/include/mock_app_mgr_client.h +++ b/services/test/mock/include/mock_app_mgr_client.h @@ -25,8 +25,8 @@ class MockAppMgrClient : public AppMgrClient { public: MockAppMgrClient(); ~MockAppMgrClient(); - MOCK_METHOD5(LoadAbility, AppMgrResultCode(const sptr &, const sptr &, - const AbilityInfo &, const ApplicationInfo &, int32_t uid)); + MOCK_METHOD4(LoadAbility, AppMgrResultCode(const sptr &, const sptr &, + const AbilityInfo &, const ApplicationInfo &)); MOCK_METHOD1(TerminateAbility, AppMgrResultCode(const sptr &)); MOCK_METHOD2(UpdateAbilityState, AppMgrResultCode(const sptr &token, const AbilityState state)); MOCK_METHOD1(KillApplication, AppMgrResultCode(const std::string &)); diff --git a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp index ce728edb34e..2e5de6b2087 100644 --- a/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp +++ b/services/test/moduletest/ability_mgr_service_test/ability_mgr_module_test.cpp @@ -190,7 +190,7 @@ static void OnStartAms() AbilityMgrModuleTest::abilityMgrServ_->GetGlobalConfiguration(); int userId = AbilityMgrModuleTest::abilityMgrServ_->GetUserId(); - AbilityMgrModuleTest::abilityMgrServ_->SetStackManager(userId, true); + AbilityMgrModuleTest::abilityMgrServ_->SetStackManager(userId); AbilityMgrModuleTest::abilityMgrServ_->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(AbilityMgrModuleTest::abilityMgrServ_->systemAppManager_); @@ -285,7 +285,7 @@ std::shared_ptr AbilityMgrModuleTest::GreatePageAbility( const std::string &abilityName, const std::string &bundleName) { Want want = CreateWant(abilityName, bundleName); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); int testRequestCode = 1; SetActive(); abilityMgrServ_->StartAbility(want, testRequestCode); @@ -329,8 +329,7 @@ void AbilityMgrModuleTest::MockDataAbilityLoadHandlerInner(bool &testFailed, spt const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo, - int32_t uid) { + const ApplicationInfo &appInfo) { dataAbilityToken = token; testFailed = testFailed || (abilityInfo.type != AbilityType::DATA); std::thread(&AbilityManagerService::AttachAbilityThread, abilityMgrServ.get(), mockDataAbilityScheduler, token) @@ -338,7 +337,7 @@ void AbilityMgrModuleTest::MockDataAbilityLoadHandlerInner(bool &testFailed, spt return AppMgrResultCode::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockLoadAbility)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockLoadAbility)); int counts = 2; EXPECT_CALL(*mockAppMgrClient_, UpdateAbilityState(_, _)) .Times(counts) @@ -386,15 +385,14 @@ void AbilityMgrModuleTest::MockServiceAbilityLoadHandlerInner( auto mockHandler = [&testResult, &bundleName, &abilityName, &testToken](const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo, - int32_t uid) { + const ApplicationInfo &appInfo) { testToken = token; testResult = !!testToken && abilityInfo.bundleName == bundleName && abilityInfo.name == abilityName && appInfo.bundleName == bundleName; return AppMgrResultCode::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); } void AbilityMgrModuleTest::CreateServiceRecord(std::shared_ptr &record, Want &want, @@ -549,15 +547,14 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_001, TestSize.Level1) auto mockHandler = [&](const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo, - int32_t uid) { + const ApplicationInfo &appInfo) { testToken = token; testResult = !!testToken && abilityInfo.bundleName == bundleName && abilityInfo.name == abilityName && appInfo.bundleName == bundleName; return AppMgrResultCode::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); @@ -915,7 +912,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_009, TestSize.Level1) const sptr callback(new AbilityConnectionProxy(stub)); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); abilityMgrServ_->ConnectAbility(want, callback, nullptr); std::shared_ptr record = abilityMgrServ_->connectManager_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -979,7 +976,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_010, TestSize.Level1) abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(2); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(2); abilityMgrServ_->ConnectAbility(want1, callback1, nullptr); abilityMgrServ_->ConnectAbility(want2, callback1, nullptr); abilityMgrServ_->ConnectAbility(want1, callback2, nullptr); @@ -1039,14 +1036,13 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_011, TestSize.Level1) auto mockHandler = [&](const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo, - int32_t uid) { + const ApplicationInfo &appInfo) { testToken = token; testResult = !!testToken && abilityInfo.bundleName == bundleName && abilityInfo.name == abilityName && appInfo.bundleName == bundleName; return AppMgrResultCode::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); int testRequestCode = 123; SetActive(); @@ -1111,14 +1107,13 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_012, TestSize.Level1) auto mockHandler = [&](const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo, - int32_t uid) { + const ApplicationInfo &appInfo) { testToken = token; testResult = !!testToken && abilityInfo.bundleName == bundleName && abilityInfo.name == abilityName && appInfo.bundleName == bundleName; return AppMgrResultCode::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); @@ -1189,7 +1184,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_013, TestSize.Level1) Want want2 = CreateWant(abilityName2, bundleName2); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(2); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(2); int testRequestCode = 123; abilityMgrServ_->StartAbility(want1, testRequestCode); abilityMgrServ_->StartAbility(want2, testRequestCode); @@ -1222,7 +1217,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_014, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); std::shared_ptr record = abilityMgrServ_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -1268,7 +1263,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_015, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); std::shared_ptr record = abilityMgrServ_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -1313,7 +1308,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_016, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); std::shared_ptr record = abilityMgrServ_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -1362,7 +1357,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_017, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); std::shared_ptr record = abilityMgrServ_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -1411,7 +1406,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_018, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); int testRequestCode = 123; SetActive(); abilityMgrServ_->StartAbility(want, testRequestCode); @@ -1482,7 +1477,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_019, TestSize.Level1) Want want = CreateWant(abilityName, bundleName); EXPECT_TRUE(abilityMgrServ_); abilityMgrServ_->RemoveAllServiceRecord(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); int testRequestCode = 123; abilityMgrServ_->StartAbility(want, testRequestCode); std::shared_ptr record = abilityMgrServ_->GetServiceRecordByElementName(want.GetElement().GetURI()); @@ -1552,7 +1547,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_020, TestSize.Level3) sptr stub(new MockAbilityConnectCallbackStub()); const sptr callback(new AbilityConnectionProxy(stub)); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); abilityMgrServ_->ConnectAbility(want, callback, nullptr); EXPECT_EQ((std::size_t)1, abilityMgrServ_->connectManager_->connectMap_.size()); EXPECT_EQ((std::size_t)1, abilityMgrServ_->connectManager_->serviceMap_.size()); @@ -1599,7 +1594,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_021, TestSize.Level1) Want want2 = CreateWant(abilityName2, bundleName2); sptr scheduler = new MockAbilityScheduler(); EXPECT_TRUE(scheduler); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(2); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(2); EXPECT_CALL(*mockAppMgrClient_, AbilityAttachTimeOut(_)).Times(1); EXPECT_CALL(*mockAppMgrClient_, UpdateAbilityState(_, _)).Times(2); EXPECT_CALL(*scheduler, ScheduleAbilityTransaction(_, _)).Times(1); @@ -1645,7 +1640,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_022, TestSize.Level1) Want want2 = CreateWant(abilityName2, bundleName2); sptr scheduler = new MockAbilityScheduler(); EXPECT_TRUE(scheduler); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(2); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(2); EXPECT_CALL(*mockAppMgrClient_, AbilityAttachTimeOut(_)).Times(1); EXPECT_CALL(*mockAppMgrClient_, UpdateAbilityState(_, _)).Times(1); EXPECT_CALL(*scheduler, ScheduleAbilityTransaction(_, _)).Times(2); @@ -1682,7 +1677,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_023, TestSize.Level1) EXPECT_TRUE(abilityMgrServ_); EXPECT_TRUE(mockAppMgrClient_); ClearStack(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); Want want = CreateWant("RadioTopAbility", COM_IX_HIRADIO); abilityMgrServ_->StartAbility(want); auto testAbilityRecord = GetTopAbility(); @@ -1710,7 +1705,7 @@ HWTEST_F(AbilityMgrModuleTest, ability_mgr_service_test_024, TestSize.Level1) auto stackManager = abilityMgrServ_->GetStackManager(); EXPECT_TRUE(stackManager); sptr scheduler = new MockAbilityScheduler(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); EXPECT_CALL(*scheduler, ScheduleAbilityTransaction(_, _)).Times(1); EXPECT_CALL(*scheduler, AsObject()).Times(2); Want want = CreateWant("PhoneAbility1", COM_IX_PHONE); @@ -1811,7 +1806,7 @@ HWTEST_F(AbilityMgrModuleTest, UpdateConfiguration_028, TestSize.Level1) std::string bundleName = "com.ix.hiMusic"; SetActive(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); EXPECT_CALL(*mockAppMgrClient_, UpdateAbilityState(_, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); Want want = CreateWant(abilityName, bundleName); auto startRef = abilityMgrServ_->StartAbility(want); @@ -1869,7 +1864,7 @@ HWTEST_F(AbilityMgrModuleTest, UpdateConfiguration_029, TestSize.Level1) std::string bundleName = "com.ix.hiService"; SetActive(); - EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _, _)).Times(1); + EXPECT_CALL(*mockAppMgrClient_, LoadAbility(_, _, _, _)).Times(1); EXPECT_CALL(*mockAppMgrClient_, UpdateAbilityState(_, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); Want want = CreateWant(abilityName, bundleName); auto startRef = abilityMgrServ_->StartAbility(want); diff --git a/services/test/moduletest/ability_record_test/ability_record_module_test.cpp b/services/test/moduletest/ability_record_test/ability_record_module_test.cpp index 4f9acc51469..46e23d75fc9 100644 --- a/services/test/moduletest/ability_record_test/ability_record_module_test.cpp +++ b/services/test/moduletest/ability_record_test/ability_record_module_test.cpp @@ -239,8 +239,7 @@ HWTEST_F(AbilityRecordModuleTest, LoadAbility_001, TestSize.Level3) auto mockHandler = [&](const sptr &token, const sptr &preToken, const AbilityInfo &abilityInfo, - const ApplicationInfo &appInfo, - int32_t uid) { + const ApplicationInfo &appInfo) { if (abilityInfo != abilityRequest.abilityInfo) { return static_cast(ERR_INVALID_VALUE); } @@ -250,7 +249,7 @@ HWTEST_F(AbilityRecordModuleTest, LoadAbility_001, TestSize.Level3) return AppExecFwk::RESULT_OK; }; - EXPECT_CALL(*mockAppMgrClient, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); + EXPECT_CALL(*mockAppMgrClient, LoadAbility(_, _, _, _)).Times(1).WillOnce(Invoke(mockHandler)); auto appScheduler = DelayedSingleton::GetInstance(); auto backupAppMgrClient = std::move(appScheduler->appMgrClient_); @@ -712,4 +711,4 @@ HWTEST_F(AbilityRecordModuleTest, Dump_001, TestSize.Level2) } } // namespace AAFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp b/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp index 8ed6a5f2564..85fff73c8f3 100644 --- a/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp +++ b/services/test/moduletest/ability_stack_test/ability_stack_module_test.cpp @@ -97,7 +97,7 @@ void AbilityStackModuleTest::OnStartabilityMs(std::shared_ptrpendingWantManager_); int userId = abilityMs->GetUserId(); - abilityMs->SetStackManager(userId, true); + abilityMs->SetStackManager(userId); abilityMs->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(abilityMs->systemAppManager_); diff --git a/services/test/moduletest/dump_module_test/dump_module_test.cpp b/services/test/moduletest/dump_module_test/dump_module_test.cpp index 894ad09e12f..96601afe88b 100644 --- a/services/test/moduletest/dump_module_test/dump_module_test.cpp +++ b/services/test/moduletest/dump_module_test/dump_module_test.cpp @@ -137,7 +137,7 @@ void DumpModuleTest::OnStartAms() EXPECT_TRUE(g_abilityMs->pendingWantManager_); int userId = g_abilityMs->GetUserId(); - g_abilityMs->SetStackManager(userId, true); + g_abilityMs->SetStackManager(userId); g_abilityMs->systemAppManager_ = std::make_shared(userId); EXPECT_TRUE(g_abilityMs->systemAppManager_); diff --git a/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp b/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp index 67d8098be67..b4732de8c88 100644 --- a/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp +++ b/services/test/moduletest/panding_want_manager_test/panding_want_manager_test.cpp @@ -292,7 +292,7 @@ HWTEST_F(PandingWantManagerTest, pending_want_mgr_test_001, TestSize.Level1) EXPECT_NE(pandingWant, nullptr); // ams mock - EXPECT_CALL(*appClient, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); + EXPECT_CALL(*appClient, LoadAbility(_, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); std::shared_ptr callback; MockCompletedCallback *call = new MockCompletedCallback(); @@ -425,7 +425,7 @@ HWTEST_F(PandingWantManagerTest, pending_want_mgr_test_003, TestSize.Level1) EXPECT_NE(pandingWant, nullptr); // ams mock - EXPECT_CALL(*appClient, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); + EXPECT_CALL(*appClient, LoadAbility(_, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); std::shared_ptr callback; MockCompletedCallback *call = new MockCompletedCallback(); @@ -491,7 +491,7 @@ HWTEST_F(PandingWantManagerTest, pending_want_mgr_test_004, TestSize.Level1) EXPECT_NE(pandingWant, nullptr); // ams mock - EXPECT_CALL(*appClient, LoadAbility(_, _, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); + EXPECT_CALL(*appClient, LoadAbility(_, _, _, _)).Times(1).WillOnce(Return(AppMgrResultCode::RESULT_OK)); std::shared_ptr callback; MockCompletedCallback *call = new MockCompletedCallback(); @@ -731,4 +731,4 @@ HWTEST_F(PandingWantManagerTest, pending_want_mgr_test_007, TestSize.Level1) EXPECT_EQ(wantAgent3->GetPendingWant()->GetTarget(), nullptr); } } // namespace AAFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file -- Gitee From 84fbd7434579f14261c46a50a940fef071ac2a64 Mon Sep 17 00:00:00 2001 From: wangdongdong Date: Wed, 12 Jan 2022 15:31:26 +0800 Subject: [PATCH 10/11] Signed-off-by: wangdongdong Change-Id: Ibbfadcce94d10df2e99af7e4f98ffee4bc185349 Signed-off-by: wangdongdong Change-Id: Ia17fda0adcef8d18f8b882a9ad39adb0d7b35425 --- .../kits/ability/native/include/ability.h | 16 ++++ .../include/ability_runtime/js_ability.h | 1 + .../distributed/continuation_manager.h | 8 +- .../kits/ability/native/src/ability.cpp | 23 +++++ .../native/src/ability_runtime/js_ability.cpp | 34 ++++++++ .../distributed/continuation_handler.cpp | 12 +-- .../distributed/continuation_manager.cpp | 84 ++++++++++++++++++- interfaces/kits/napi/aafwk/ability/ability.js | 1 + 8 files changed, 170 insertions(+), 9 deletions(-) mode change 100644 => 100755 frameworks/kits/ability/native/include/ability.h mode change 100644 => 100755 frameworks/kits/ability/native/include/ability_runtime/js_ability.h mode change 100644 => 100755 interfaces/kits/napi/aafwk/ability/ability.js diff --git a/frameworks/kits/ability/native/include/ability.h b/frameworks/kits/ability/native/include/ability.h old mode 100644 new mode 100755 index b078ab08d93..332ee388ba3 --- a/frameworks/kits/ability/native/include/ability.h +++ b/frameworks/kits/ability/native/include/ability.h @@ -1274,6 +1274,22 @@ public: */ std::weak_ptr GetContinuationRegisterManager(); + /** + * @brief Prepare user data of local Ability. + * + * @param wantParams Indicates the user data to be saved. + * @return If the ability is willing to continue and data saved successfully, it returns true; + * otherwise, it returns false. + */ + virtual bool OnContinue(WantParams &wantParams); + + /** + * @brief Get page ability stack info. + * + * @return A string represents page ability stack info, empty if failed; + */ + virtual const std::string& GetContentInfo(); + /** * @brief Migrates this ability to the given device on the same distributed network. The ability to migrate and its * ability slices must implement the IAbilityContinuation interface. diff --git a/frameworks/kits/ability/native/include/ability_runtime/js_ability.h b/frameworks/kits/ability/native/include/ability_runtime/js_ability.h old mode 100644 new mode 100755 index 54cc070f8c2..7c2d5204f3d --- a/frameworks/kits/ability/native/include/ability_runtime/js_ability.h +++ b/frameworks/kits/ability/native/include/ability_runtime/js_ability.h @@ -51,6 +51,7 @@ public: void OnForeground(const Want &want) override; void OnBackground() override; + bool OnContinue(WantParams &wantParams) override; void OnAbilityResult(int requestCode, int resultCode, const Want &resultData) override; void OnRequestPermissionsFromUserResult( diff --git a/frameworks/kits/ability/native/include/continuation/distributed/continuation_manager.h b/frameworks/kits/ability/native/include/continuation/distributed/continuation_manager.h index 2cf3a35a47b..e47be5e1a0b 100644 --- a/frameworks/kits/ability/native/include/continuation/distributed/continuation_manager.h +++ b/frameworks/kits/ability/native/include/continuation/distributed/continuation_manager.h @@ -51,7 +51,11 @@ public: bool StartContinuation(); - bool OnContinue(WantParams &wantParams); + int32_t OnContinue(WantParams &wantParams); + + int32_t OnStartAndSaveData(WantParams &wantParams); + + int32_t OnContinueAndGetContent(WantParams &wantParams); bool SaveData(WantParams &saveData); @@ -97,6 +101,8 @@ private: bool DoRestoreFromRemote(const WantParams &restoreData); + bool GetContentInfo(WantParams &wantParams); + sptr continueToken_ = nullptr; std::weak_ptr ability_; std::weak_ptr abilityInfo_; diff --git a/frameworks/kits/ability/native/src/ability.cpp b/frameworks/kits/ability/native/src/ability.cpp index d266dca5e9c..0a9b7dfa273 100755 --- a/frameworks/kits/ability/native/src/ability.cpp +++ b/frameworks/kits/ability/native/src/ability.cpp @@ -1614,6 +1614,29 @@ std::weak_ptr Ability::GetContinuationRegisterMana return continuationRegisterManager; } +/** + * @brief Callback function to ask the user to prepare for the migration . + * + * @return If the user allows migration and saves data suscessfully, it returns true; otherwise, it returns false. + */ +bool Ability::OnContinue(WantParams &wantParams) +{ + return false; +} + +/** + * @brief Get page ability stack info. + * + * @return A string represents page ability stack info, empty if failed; + */ +const std::string& Ability::GetContentInfo() +{ + if (scene_ == nullptr) { + return ""; + } + return scene_->GetContentInfo(); +} + /** * @brief Migrates this ability to the given device on the same distributed network. The ability to migrate and its * ability slices must implement the IAbilityContinuation interface. diff --git a/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp b/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp index e087171f79f..44a52416f2c 100755 --- a/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp +++ b/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp @@ -185,6 +185,40 @@ void JsAbility::OnBackground() CallObjectMethod("onBackground"); } +bool JsAbility::OnContinue(WantParams &wantParams) +{ + HandleScope handleScope(jsRuntime_); + auto& nativeEngine = jsRuntime_.GetNativeEngine(); + + NativeValue* value = jsAbilityObj_->Get(); + NativeObject* obj = ConvertNativeValueTo(value); + if (obj == nullptr) { + HILOG_ERROR("Failed to get Ability object"); + return false; + } + + NativeValue* methodOnCreate = obj->GetProperty("onContinue"); + if (methodOnCreate == nullptr) { + HILOG_ERROR("Failed to get 'onContinue' from Ability object"); + return false; + } + + napi_value napiWantParams = OHOS::AppExecFwk::WrapWantParams(reinterpret_cast(&nativeEngine), wantParams); + NativeValue* jsWantParams = reinterpret_cast(napiWantParams); + + NativeValue* result = nativeEngine.CallFunction(value, methodOnCreate, &jsWantParams, 1); + + napi_value new_napiWantParams = reinterpret_cast(jsWantParams); + OHOS::AppExecFwk::UnwrapWantParams(reinterpret_cast(&nativeEngine), new_napiWantParams, wantParams); + + NativeBoolean* boolResult = ConvertNativeValueTo(result); + if (boolResult == nullptr) { + return false; + } + + return *boolResult; +} + void JsAbility::OnAbilityResult(int requestCode, int resultCode, const Want &resultData) { HILOG_INFO("%{public}s begin.", __func__); diff --git a/frameworks/kits/ability/native/src/continuation/distributed/continuation_handler.cpp b/frameworks/kits/ability/native/src/continuation/distributed/continuation_handler.cpp index d0e424c9219..e17a54cc5d0 100644 --- a/frameworks/kits/ability/native/src/continuation/distributed/continuation_handler.cpp +++ b/frameworks/kits/ability/native/src/continuation/distributed/continuation_handler.cpp @@ -23,7 +23,6 @@ using OHOS::AAFwk::WantParams; namespace OHOS { namespace AppExecFwk { const std::string ContinuationHandler::ORIGINAL_DEVICE_ID("deviceId"); -const int32_t ABILITY_REJECTED = 29360197; ContinuationHandler::ContinuationHandler( std::weak_ptr &continuationManager, std::weak_ptr &ability) { @@ -52,14 +51,15 @@ bool ContinuationHandler::HandleStartContinuationWithStack(const sptrOnContinue(wantParams)) { - APP_LOGI("HandleStartContinuationWithStack: OnContinue failed, BundleName = %{public}s, ClassName= %{public}s", + int32_t status = continuationManagerTmp->OnContinue(wantParams); + if (status != ERR_OK) { + APP_LOGI("OnContinue failed, BundleName = %{public}s, ClassName= %{public}s, status: %{public}d", abilityInfo_->bundleName.c_str(), - abilityInfo_->name.c_str()); - status = ABILITY_REJECTED; + abilityInfo_->name.c_str(), + status); } Want want = SetWantParams(wantParams); diff --git a/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp b/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp index dcb69ac750f..b796eec8e64 100644 --- a/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp +++ b/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp @@ -23,12 +23,19 @@ #include "distributed_client.h" #include "operation_builder.h" #include "string_ex.h" +#include "string_wrapper.h" #include "want.h" namespace OHOS { namespace AppExecFwk { const int ContinuationManager::TIMEOUT_MS_WAIT_DMS_NOTIFY_CONTINUATION_COMPLETE = 25000; const int ContinuationManager::TIMEOUT_MS_WAIT_REMOTE_NOTIFY_BACK = 6000; +const int TARGET_VERSION_THRESHOLDS = 8; +const std::string PAGE_STACK_PROPERTY_NAME = "pageStack"; +const int32_t CONTINUE_ABILITY_REJECTED = 29360197; +const int32_t CONTINUE_SAVE_DATA_FAILED = 29360198; +const int32_t CONTINUE_ON_CONTINUE_FAILED = 29360199; +const int32_t CONTINUE_GET_CONTENT_FAILED = 29360200; ContinuationManager::ContinuationManager() { @@ -120,14 +127,87 @@ bool ContinuationManager::HandleContinueAbilityWithStack(const std::string &devi return true; } -bool ContinuationManager::OnContinue(WantParams &wantParams) +int32_t ContinuationManager::OnStartAndSaveData(WantParams &wantParams) { + APP_LOGI("%{public}s called begin", __func__); + if (!StartContinuation()) { + APP_LOGE("Ability rejected."); + return CONTINUE_ABILITY_REJECTED; + } + if (!SaveData(wantParams)) { + APP_LOGE("SaveData failed."); + return CONTINUE_SAVE_DATA_FAILED; + } + APP_LOGI("%{public}s called end", __func__); + return ERR_OK; +} + +int32_t ContinuationManager::OnContinueAndGetContent(WantParams &wantParams) +{ + APP_LOGI("%{public}s called begin", __func__); std::shared_ptr ability = nullptr; ability = ability_.lock(); if (ability == nullptr) { - APP_LOGE("ContinuationManager::CheckContinuationIllegal failed. ability is nullptr"); + APP_LOGE("ability is nullptr"); + return ERR_INVALID_VALUE; + } + + bool status; + APP_LOGI("OnContinue begin"); + status = ability->OnContinue(wantParams); + APP_LOGI("OnContinue end"); + if (!status) { + APP_LOGE("OnContinue failed."); + return CONTINUE_ON_CONTINUE_FAILED; + } + + status = GetContentInfo(wantParams); + if (!status) { + APP_LOGE("GetContentInfo failed."); + return CONTINUE_GET_CONTENT_FAILED; + } + APP_LOGI("%{public}s called end", __func__); + return ERR_OK; +} + +int32_t ContinuationManager::OnContinue(WantParams &wantParams) +{ + APP_LOGI("%{public}s called begin", __func__); + std::shared_ptr ability = nullptr; + ability = ability_.lock(); + if (ability == nullptr) { + APP_LOGE("ability is nullptr"); + return ERR_INVALID_VALUE; + } + + int32_t apiVersion = ability->GetCompatibleVersion(); + APP_LOGI("ability api version is %{public}d", apiVersion); + if (apiVersion < TARGET_VERSION_THRESHOLDS) { + return OnStartAndSaveData(wantParams); + } else { + return OnContinueAndGetContent(wantParams); + } +} + +bool ContinuationManager::GetContentInfo(WantParams &wantParams) +{ + APP_LOGI("%{public}s called begin", __func__); + std::shared_ptr ability = nullptr; + ability = ability_.lock(); + if (ability == nullptr) { + APP_LOGE("ability is nullptr"); return false; } + + std::string pageStack = ability->GetContentInfo(); + if (pageStack.empty()) { + APP_LOGE("GetContentInfo failed."); + return false; + } + APP_LOGI("ability pageStack: %{public}s", pageStack.c_str()); + wantParams.SetParam(PAGE_STACK_PROPERTY_NAME, String::Box(pageStack)); + + APP_LOGI("%{public}s called end", __func__); return true; } diff --git a/interfaces/kits/napi/aafwk/ability/ability.js b/interfaces/kits/napi/aafwk/ability/ability.js old mode 100644 new mode 100755 index 01d390e9d6e..175bce40430 --- a/interfaces/kits/napi/aafwk/ability/ability.js +++ b/interfaces/kits/napi/aafwk/ability/ability.js @@ -22,6 +22,7 @@ class Ability { onForeground(want) {} onBackground() {} onWindowStageRestore(windowStage) {} + onContinue(wantParams) {} } export default Ability -- Gitee From 30a3973ca5249c167d574015026393ebd6696488 Mon Sep 17 00:00:00 2001 From: wangdongdong Date: Thu, 13 Jan 2022 11:57:10 +0800 Subject: [PATCH 11/11] Signed-off-by: wangdongdong Change-Id: I0928cd2c67b25c8f6dabc8043b3abdd23f158019 Signed-off-by: wangdongdong Change-Id: Ia15b60801949e495421616afb07ff71ca8fff9ec --- .../kits/ability/native/src/ability_impl.cpp | 3 ++- .../distributed/continuation_manager.cpp | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/frameworks/kits/ability/native/src/ability_impl.cpp b/frameworks/kits/ability/native/src/ability_impl.cpp index feb6cc865b5..046828af451 100755 --- a/frameworks/kits/ability/native/src/ability_impl.cpp +++ b/frameworks/kits/ability/native/src/ability_impl.cpp @@ -66,7 +66,8 @@ void AbilityImpl::Start(const Want &want) return; } - if (ability_->GetAbilityInfo()->type == AbilityType::PAGE) { + if ((ability_->GetAbilityInfo()->type == AbilityType::PAGE) && + (ability_->GetCompatibleVersion() < TARGET_VERSION_THRESHOLDS)) { ability_->HandleCreateAsContinuation(want); } diff --git a/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp b/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp index b796eec8e64..4c83c9a564a 100644 --- a/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp +++ b/frameworks/kits/ability/native/src/continuation/distributed/continuation_manager.cpp @@ -89,10 +89,6 @@ std::string ContinuationManager::GetOriginalDeviceId() void ContinuationManager::ContinueAbilityWithStack(const std::string &deviceId) { APP_LOGI("%{public}s called begin", __func__); - if (CheckContinuationIllegal()) { - APP_LOGE("ContinueAbilityWithStack failed. Ability not available to continueAbility."); - return; - } HandleContinueAbilityWithStack(deviceId); APP_LOGI("%{public}s called end", __func__); @@ -130,11 +126,18 @@ bool ContinuationManager::HandleContinueAbilityWithStack(const std::string &devi int32_t ContinuationManager::OnStartAndSaveData(WantParams &wantParams) { APP_LOGI("%{public}s called begin", __func__); - if (!StartContinuation()) { + std::shared_ptr ability = nullptr; + ability = ability_.lock(); + if (ability == nullptr) { + APP_LOGE("ability is nullptr"); + return ERR_INVALID_VALUE; + } + + if (!ability->OnStartContinuation()) { APP_LOGE("Ability rejected."); return CONTINUE_ABILITY_REJECTED; } - if (!SaveData(wantParams)) { + if (!ability->OnSaveData(wantParams)) { APP_LOGE("SaveData failed."); return CONTINUE_SAVE_DATA_FAILED; } -- Gitee