!9239 免安装结果监听器新增校验

Merge pull request !9239 from donglin/free_install
This commit is contained in:
openharmony_ci 2024-07-09 07:14:45 +00:00 committed by Gitee
commit 30ffa3b64a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
38 changed files with 271 additions and 284 deletions

View File

@ -1418,10 +1418,14 @@ void JsNapiCommon::AddFreeInstallObserver(napi_env env, const AAFwk::Want &want,
{
// adapter free install async return install and start result
TAG_LOGD(AAFwkTag::JSNAPI, "AddFreeInstallObserver start.");
if (ability_ == nullptr) {
TAG_LOGE(AAFwkTag::JSNAPI, "the ability is nullptr");
return;
}
int ret = 0;
if (freeInstallObserver_ == nullptr) {
freeInstallObserver_ = new JsFreeInstallObserver(env);
ret = AAFwk::AbilityManagerClient::GetInstance()->AddFreeInstallObserver(freeInstallObserver_);
ret = ability_->AddFreeInstallObserver(freeInstallObserver_);
}
if (ret != ERR_OK) {

View File

@ -1008,6 +1008,15 @@ ErrCode AbilityContextImpl::ChangeAbilityVisibility(bool isShow)
return err;
}
ErrCode AbilityContextImpl::AddFreeInstallObserver(const sptr<IFreeInstallObserver> &observer)
{
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->AddFreeInstallObserver(token_, observer);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::CONTEXT, "AddFreeInstallObserver error, ret: %{public}d", ret);
}
return ret;
}
ErrCode AbilityContextImpl::OpenAtomicService(AAFwk::Want& want, const AAFwk::StartOptions &options, int requestCode,
RuntimeTask &&task)
{

View File

@ -448,6 +448,11 @@ ErrCode Ability::StartAbility(const Want &want, AbilityStartSetting abilityStart
return err;
}
ErrCode Ability::AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> observer)
{
return AbilityContext::AddFreeInstallObserver(observer);
}
std::string Ability::GetType(const Uri &uri)
{
return "";

View File

@ -329,5 +329,14 @@ sptr<IRemoteObject> AbilityContext::GetSessionToken()
std::lock_guard lock(sessionTokenMutex_);
return sessionToken_;
}
int32_t AbilityContext::AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
{
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->AddFreeInstallObserver(token_, observer);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::CONTEXT, "AddFreeInstallObserver error, ret: %{public}d", ret);
}
return ret;
}
} // namespace AppExecFwk
} // namespace OHOS

View File

@ -524,12 +524,10 @@ bool JsAbilityContext::CreateOpenLinkTask(const napi_env &env, const napi_value
TAG_LOGW(AAFwkTag::CONTEXT, "wrap abilityResult error");
asyncTask->Reject(env, CreateJsError(env, AbilityErrorCode::ERROR_CODE_INNER));
return;
} else {
isInner ? asyncTask->Reject(env, CreateJsErrorByNativeErr(env, resultCode)) :
asyncTask->ResolveWithNoError(env, abilityResult);
}
if (isInner) {
asyncTask->Reject(env, CreateJsErrorByNativeErr(env, resultCode));
return;
}
asyncTask->ResolveWithNoError(env, abilityResult);
};
curRequestCode_ = (curRequestCode_ == INT_MAX) ? 0 : (curRequestCode_ + 1);
requestCode = curRequestCode_;
@ -1421,11 +1419,8 @@ napi_value JsAbilityContext::OnTerminateSelf(napi_env env, NapiCallbackInfo& inf
}
auto errcode = context->TerminateSelf();
if (errcode == 0) {
task.Resolve(env, CreateJsUndefined(env));
} else {
(errcode == 0) ? task.Resolve(env, CreateJsUndefined(env)) :
task.Reject(env, CreateJsErrorByNativeErr(env, errcode));
}
};
napi_value lastParam = (info.argc > ARGC_ZERO) ? info.argv[INDEX_ZERO] : nullptr;
@ -1528,11 +1523,8 @@ napi_value JsAbilityContext::OnReportDrawnCompleted(napi_env env, NapiCallbackIn
};
NapiAsyncTask::CompleteCallback complete = [innerErrorCode](napi_env env, NapiAsyncTask& task, int32_t status) {
if (*innerErrorCode == ERR_OK) {
task.Resolve(env, CreateJsUndefined(env));
} else {
(*innerErrorCode == ERR_OK) ? task.Resolve(env, CreateJsUndefined(env)) :
task.Reject(env, CreateJsErrorByNativeErr(env, *innerErrorCode));
}
};
napi_value lastParam = info.argv[INDEX_ZERO];
@ -1611,7 +1603,12 @@ void JsAbilityContext::AddFreeInstallObserver(napi_env env, const AAFwk::Want &w
int ret = 0;
if (freeInstallObserver_ == nullptr) {
freeInstallObserver_ = new JsFreeInstallObserver(env);
ret = AAFwk::AbilityManagerClient::GetInstance()->AddFreeInstallObserver(freeInstallObserver_);
auto context = context_.lock();
if (!context) {
TAG_LOGE(AAFwkTag::CONTEXT, "context is nullptr.");
return;
}
ret = context->AddFreeInstallObserver(freeInstallObserver_);
}
if (ret != ERR_OK) {
@ -2105,11 +2102,8 @@ napi_value JsAbilityContext::OnStartAbilityByType(napi_env env, NapiCallbackInfo
}
#ifdef SUPPORT_SCREEN
auto errcode = context->StartAbilityByType(type, wantParam, callback);
if (errcode != 0) {
task.Reject(env, CreateJsErrorByNativeErr(env, errcode));
} else {
(errcode != 0) ? task.Reject(env, CreateJsErrorByNativeErr(env, errcode)) :
task.ResolveWithNoError(env, CreateJsUndefined(env));
}
#endif
};
@ -2180,11 +2174,8 @@ napi_value JsAbilityContext::ChangeAbilityVisibility(napi_env env, NapiCallbackI
return;
}
auto errCode = context->ChangeAbilityVisibility(isShow);
if (errCode == 0) {
task.ResolveWithNoError(env, CreateJsUndefined(env));
} else {
(errCode == 0) ? task.ResolveWithNoError(env, CreateJsUndefined(env)) :
task.Reject(env, CreateJsErrorByNativeErr(env, errCode));
}
};
napi_value result = nullptr;
@ -2250,11 +2241,8 @@ napi_value JsAbilityContext::OpenAtomicServiceInner(napi_env env, NapiCallbackIn
isInner = true;
resultCode = ERR_INVALID_VALUE;
}
if (isInner) {
observer->OnInstallFinished(bundleName, abilityName, startTime, resultCode);
} else {
isInner ? observer->OnInstallFinished(bundleName, abilityName, startTime, resultCode) :
observer->OnInstallFinished(bundleName, abilityName, startTime, abilityResult);
}
};
auto context = context_.lock();
if (context == nullptr) {

View File

@ -204,7 +204,12 @@ private:
int ret = 0;
if (freeInstallObserver_ == nullptr) {
freeInstallObserver_ = new JsFreeInstallObserver(env);
ret = AAFwk::AbilityManagerClient::GetInstance()->AddFreeInstallObserver(freeInstallObserver_);
auto context = context_.lock();
if (!context) {
TAG_LOGW(AAFwkTag::SERVICE_EXT, "context is released");
return;
}
ret = context->AddFreeInstallObserver(freeInstallObserver_);
}
if (ret != ERR_OK) {

View File

@ -1055,7 +1055,13 @@ void JsUIExtensionContentSession::AddFreeInstallObserver(napi_env env,
int ret = 0;
if (freeInstallObserver_ == nullptr) {
freeInstallObserver_ = new JsFreeInstallObserver(env);
ret = AAFwk::AbilityManagerClient::GetInstance()->AddFreeInstallObserver(freeInstallObserver_);
auto context = context_.lock();
if (!context) {
TAG_LOGE(AAFwkTag::CONTEXT, "context is nullptr.");
return;
}
ret = AAFwk::AbilityManagerClient::GetInstance()->AddFreeInstallObserver(context->GetToken(),
freeInstallObserver_);
}
if (ret != ERR_OK) {

View File

@ -812,7 +812,12 @@ void JsUIExtensionContext::AddFreeInstallObserver(napi_env env, const AAFwk::Wan
int ret = 0;
if (freeInstallObserver_ == nullptr) {
freeInstallObserver_ = new JsFreeInstallObserver(env);
ret = AAFwk::AbilityManagerClient::GetInstance()->AddFreeInstallObserver(freeInstallObserver_);
auto context = context_.lock();
if (!context) {
TAG_LOGE(AAFwkTag::CONTEXT, "context is nullptr.");
return;
}
ret = context->AddFreeInstallObserver(freeInstallObserver_);
}
if (ret != ERR_OK) {

View File

@ -283,5 +283,14 @@ ErrCode UIExtensionContext::OpenLink(const AAFwk::Want& want, int requestCode)
TAG_LOGD(AAFwkTag::UI_EXT, "Called.");
return AAFwk::AbilityManagerClient::GetInstance()->OpenLink(want, token_, -1, requestCode);
}
ErrCode UIExtensionContext::AddFreeInstallObserver(const sptr<IFreeInstallObserver> &observer)
{
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->AddFreeInstallObserver(token_, observer);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::CONTEXT, "AddFreeInstallObserver error, ret: %{public}d", ret);
}
return ret;
}
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -259,5 +259,14 @@ ErrCode ServiceExtensionContext::PreStartMission(const std::string& bundleName,
TAG_LOGI(AAFwkTag::APPKIT, "End.");
return err;
}
ErrCode ServiceExtensionContext::AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
{
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->AddFreeInstallObserver(token_, observer);
if (ret != ERR_OK) {
TAG_LOGE(AAFwkTag::APPKIT, "AddFreeInstallObserver error, ret: %{public}d", ret);
}
return ret;
}
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -1181,10 +1181,12 @@ public:
/**
* @brief Add free install observer.
*
* @param callerToken The caller ability token.
* @param observer Free install observer.
* @return Returns ERR_OK on success, others on failure.
*/
ErrCode AddFreeInstallObserver(sptr<AbilityRuntime::IFreeInstallObserver> observer);
ErrCode AddFreeInstallObserver(const sptr<IRemoteObject> callToken,
const sptr<AbilityRuntime::IFreeInstallObserver> observer);
/**
* Called to verify that the MissionId is valid.

View File

@ -1150,10 +1150,12 @@ public:
/**
* Add free install observer.
*
* @param observer, the observer of the ability to free install start.
* @param callerToken, The caller ability token.
* @param observer, The observer of the ability to free install start.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
virtual int AddFreeInstallObserver(const sptr<IRemoteObject> &callerToken,
const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
{
return 0;
}

View File

@ -49,19 +49,11 @@ public:
* @param userId, user`s id.
*/
virtual void OnRemoteInstallFinished(int resultCode, const Want &want, int32_t userId) = 0;
/**
* OnRemoveTimeoutTask, BMS has connected AG.
*
* @param want, the want of the ability to free install.
*/
virtual void OnRemoveTimeoutTask(const Want &want) = 0;
protected:
enum IAtomicServiceStatusCallbackCmd {
ON_FREE_INSTALL_DONE = 0,
ON_REMOTE_FREE_INSTALL_DONE,
ON_REMOVE_TIMEOUT_TASK,
CMD_MAX,
};
};

View File

@ -52,13 +52,6 @@ public:
*/
void OnRemoteInstallFinished(int resultCode, const Want &want, int32_t userId) override;
/**
* OnRemoveTimeoutTask, BMS has connected AG.
*
* @param want, installed ability
*/
void OnRemoveTimeoutTask(const Want &want) override;
private:
int32_t SendTransactCmd(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option);
static inline BrokerDelegator<AtomicServiceStatusCallbackProxy> delegator_;

View File

@ -22,6 +22,7 @@
#include "caller_callback.h"
#include "configuration.h"
#include "context.h"
#include "free_install_observer_interface.h"
#include "iability_callback.h"
#include "js_ui_extension_callback.h"
#include "mission_info.h"
@ -175,6 +176,8 @@ public:
virtual ErrCode OpenAtomicService(AAFwk::Want& want, const AAFwk::StartOptions &options, int requestCode,
RuntimeTask &&task) = 0;
virtual ErrCode AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer) = 0;
virtual ErrCode ChangeAbilityVisibility(bool isShow) { return 0; }
/**

View File

@ -223,6 +223,7 @@ public:
ErrCode ChangeAbilityVisibility(bool isShow) override;
ErrCode OpenLink(const AAFwk::Want& want, int requestCode) override;
ErrCode AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer) override;
ErrCode OpenAtomicService(AAFwk::Want& want, const AAFwk::StartOptions &options, int requestCode,
RuntimeTask &&task) override;

View File

@ -32,6 +32,7 @@
#include "continuation_state.h"
#include "dummy_notification_request.h"
#include "fa_ability_context.h"
#include "free_install_observer_interface.h"
#include "iability_callback.h"
#include "want_agent.h"
@ -178,6 +179,7 @@ public:
using AbilityContext::StartAbility;
ErrCode StartAbility(const Want &want, AbilityStartSetting abilityStartSetting);
ErrCode AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> observer);
/**
* @brief A Page or Service ability uses this method to start a specific ability. The system locates the target
* ability from installed abilities based on the value of the want parameter and then starts it. You can specify

View File

@ -61,6 +61,8 @@ public:
*/
ErrCode StartAbility(const Want &want, int requestCode, const AbilityStartSetting &abilityStartSetting) override;
ErrCode AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer);
/**
* @brief Destroys the current ability.
*

View File

@ -20,6 +20,7 @@
#include "ability_connect_callback.h"
#include "extension_context.h"
#include "free_install_observer_interface.h"
#include "start_options.h"
#include "want.h"
#ifdef SUPPORT_SCREEN
@ -150,6 +151,8 @@ public:
ErrCode OpenAtomicService(AAFwk::Want& want, const AAFwk::StartOptions &options, int requestCode,
RuntimeTask &&task);
ErrCode AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer);
void InsertResultCallbackTask(int requestCode, RuntimeTask&& task);
void RemoveResultCallbackTask(int requestCode);

View File

@ -20,6 +20,7 @@
#include "ability_connect_callback.h"
#include "connection_manager.h"
#include "free_install_observer_interface.h"
#include "local_call_container.h"
#include "start_options.h"
#include "want.h"
@ -74,6 +75,8 @@ public:
ErrCode StartAbilityByCall(const AAFwk::Want& want, const std::shared_ptr<CallerCallBack> &callback,
int32_t accountId = DEFAULT_INVAL_VALUE);
ErrCode AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer);
/**
* caller release by callback object
*

View File

@ -886,7 +886,8 @@ public:
* @param observer the observer of ability free install start.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer) override;
virtual int AddFreeInstallObserver(const sptr<IRemoteObject> &callerToken,
const sptr<AbilityRuntime::IFreeInstallObserver> &observer) override;
/**
* Called when client complete dump.

View File

@ -1300,7 +1300,8 @@ public:
* @param observer the observer of ability free install start.
* @return Returns ERR_OK on success, others on failure.
*/
virtual int AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer) override;
virtual int AddFreeInstallObserver(const sptr<IRemoteObject> &callerToken,
const sptr<AbilityRuntime::IFreeInstallObserver> &observer) override;
/**
* Check the uid is background task uid.

View File

@ -31,7 +31,7 @@ class FreeInstallManager;
*/
class AtomicServiceStatusCallback : public AtomicServiceStatusCallbackStub {
public:
AtomicServiceStatusCallback(const std::weak_ptr<FreeInstallManager> &server, bool isAsync);
AtomicServiceStatusCallback(const std::weak_ptr<FreeInstallManager> &server, bool isAsync, int32_t recordId);
virtual ~AtomicServiceStatusCallback() = default;
/**
@ -52,16 +52,10 @@ public:
*/
void OnRemoteInstallFinished(int resultCode, const Want &want, int32_t userId) override;
/**
* OnRemoveTimeoutTask, BMS has connected AG.
*
* @param want, installed ability
*/
void OnRemoveTimeoutTask(const Want &want) override;
private:
std::weak_ptr<FreeInstallManager> server_;
bool isAsync_;
int32_t recordId_ = -1;
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2022-2024 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
@ -65,7 +65,7 @@ public:
* @param want, installed ability.
* @param userId, user`s id.
*/
void OnInstallFinished(int resultCode, const Want &want, int32_t userId, bool isAsync = false);
void OnInstallFinished(int32_t recordId, int resultCode, const Want &want, int32_t userId, bool isAsync = false);
/**
* OnRemoteInstallFinished, DMS has finished.
@ -74,7 +74,7 @@ public:
* @param want, installed ability.
* @param userId, user`s id.
*/
void OnRemoteInstallFinished(int resultCode, const Want &want, int32_t userId);
void OnRemoteInstallFinished(int32_t recordId, int resultCode, const Want &want, int32_t userId);
/**
* Start to free install.
@ -132,13 +132,8 @@ public:
* @param observer, the observer of the ability to free install.
* @return Returns ERR_OK on success, others on failure.
*/
int AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer);
/**
* Remove the timeout task when bms connect FA center.
* @param want, the want of the ability to free install.
*/
void OnRemoveTimeoutTask(const Want &want);
int AddFreeInstallObserver(const sptr<IRemoteObject> &callerToken,
const sptr<AbilityRuntime::IFreeInstallObserver> &observer);
/**
* Get free install task info.
@ -218,7 +213,7 @@ private:
int NotifyDmsCallback(const Want &want, int resultCode);
bool IsTopAbility(const sptr<IRemoteObject> &callerToken);
void NotifyFreeInstallResult(const Want &want, int resultCode, bool isAsync = false);
void NotifyFreeInstallResult(int32_t recordId, const Want &want, int resultCode, bool isAsync = false);
FreeInstallInfo BuildFreeInstallInfo(const Want &want, int32_t userId, int requestCode,
const sptr<IRemoteObject> &callerToken, bool isAsync, uint32_t specifyTokenId = 0,
bool isOpenAtomicServiceShortUrl = false, std::shared_ptr<Want> originalWant = nullptr);
@ -229,21 +224,21 @@ private:
void PostUpgradeAtomicServiceTask(int resultCode, const Want &want, int32_t userId);
void PostTimeoutTask(const Want &want);
void HandleTimeoutTask(const std::string &bundleName, const std::string &abilityName, const std::string &startTime);
void RemoveTimeoutTask(const std::string &bundleName, const std::string &abilityName, const std::string &startTime);
void StartAbilityByFreeInstall(FreeInstallInfo &info, std::string &bundleName, std::string &abilityName,
std::string &startTime);
void StartAbilityByPreInstall(FreeInstallInfo &info, std::string &bundleName, std::string &abilityName,
std::string &startTime);
void StartAbilityByPreInstall(int32_t recordId, FreeInstallInfo &info, std::string &bundleName,
std::string &abilityName, std::string &startTime);
int32_t UpdateElementName(Want &want, int32_t userId) const;
void HandleFreeInstallResult(FreeInstallInfo &freeInstallInfo, int resultCode, bool isAsync);
void HandleOnFreeInstallSuccess(FreeInstallInfo &freeInstallInfo, bool isAsync);
void HandleOnFreeInstallFail(FreeInstallInfo &freeInstallInfo, int resultCode, bool isAsync);
void HandleFreeInstallResult(int32_t recordId, FreeInstallInfo &freeInstallInfo, int resultCode, bool isAsync);
void HandleOnFreeInstallSuccess(int32_t recordId, FreeInstallInfo &freeInstallInfo, bool isAsync);
void HandleOnFreeInstallFail(int32_t recordId, FreeInstallInfo &freeInstallInfo, int resultCode, bool isAsync);
void NotifySCBToHandleException(const FreeInstallInfo &info, int resultCode);
void StartAbilityByConvertedWant(FreeInstallInfo &info, const std::string &startTime);
void StartAbilityByOriginalWant(FreeInstallInfo &info, const std::string &startTime);
bool VerifyStartFreeInstallPermission(const sptr<IRemoteObject> &callerToken);
int32_t GetRecordIdByToken(const sptr<IRemoteObject> &callerToken);
};
} // namespace AAFwk
} // namespace OHOS

View File

@ -18,7 +18,7 @@
#include <map>
#include <mutex>
#include <vector>
#include <unordered_map>
#include "cpp/mutex.h"
#include "free_install_observer_interface.h"
@ -30,30 +30,28 @@ using namespace OHOS::AbilityRuntime;
class FreeInstallObserverManager : public std::enable_shared_from_this<FreeInstallObserverManager> {
DECLARE_DELAYED_SINGLETON(FreeInstallObserverManager)
public:
int32_t AddObserver(const sptr<IFreeInstallObserver> &observer);
int32_t AddObserver(int32_t recordId, const sptr<IFreeInstallObserver> &observer);
int32_t RemoveObserver(const sptr<IFreeInstallObserver> &observer);
void OnInstallFinished(const std::string &bundleName, const std::string &abilityName,
void OnInstallFinished(int32_t recordId, const std::string &bundleName, const std::string &abilityName,
const std::string &startTime, const int &resultCode);
void OnInstallFinishedByUrl(const std::string &startTime, const std::string &url,
void OnInstallFinishedByUrl(int32_t recordId, const std::string &startTime, const std::string &url,
const int &resultCode);
private:
bool ObserverExistLocked(const sptr<IFreeInstallObserver> &observer);
void OnObserverDied(const wptr<IRemoteObject> &remote);
void HandleOnInstallFinished(const std::string &bundleName, const std::string &abilityName,
void HandleOnInstallFinished(int32_t recordId, const std::string &bundleName, const std::string &abilityName,
const std::string &startTime, const int &resultCode);
void HandleOnInstallFinishedByUrl(const std::string &startTime, const std::string &url,
void HandleOnInstallFinishedByUrl(int32_t recordId, const std::string &startTime, const std::string &url,
const int &resultCode);
ffrt::mutex observerLock_;
sptr<IRemoteObject::DeathRecipient> deathRecipient_;
std::vector<sptr<IFreeInstallObserver>> observerList_;
std::unordered_map<int32_t, sptr<IFreeInstallObserver>> observerMap_;
};
class FreeInstallObserverRecipient : public IRemoteObject::DeathRecipient {

View File

@ -1513,12 +1513,13 @@ void AbilityManagerClient::HandleDlpApp(Want &want)
#endif // WITH_DLP
}
ErrCode AbilityManagerClient::AddFreeInstallObserver(sptr<AbilityRuntime::IFreeInstallObserver> observer)
ErrCode AbilityManagerClient::AddFreeInstallObserver(const sptr<IRemoteObject> callerToken,
const sptr<AbilityRuntime::IFreeInstallObserver> observer)
{
TAG_LOGI(AAFwkTag::ABILITYMGR, "call");
auto abms = GetAbilityManager();
CHECK_POINTER_RETURN_NOT_CONNECTED(abms);
return abms->AddFreeInstallObserver(observer);
return abms->AddFreeInstallObserver(callerToken, observer);
}
int32_t AbilityManagerClient::IsValidMissionIds(

View File

@ -3884,7 +3884,8 @@ int AbilityManagerProxy::FreeInstallAbilityFromRemote(const Want &want, const sp
return reply.ReadInt32();
}
int AbilityManagerProxy::AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
int AbilityManagerProxy::AddFreeInstallObserver(const sptr<IRemoteObject> &callerToken,
const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
{
MessageParcel data;
MessageParcel reply;
@ -3899,6 +3900,18 @@ int AbilityManagerProxy::AddFreeInstallObserver(const sptr<AbilityRuntime::IFree
return INNER_ERR;
}
if (callerToken) {
if (!data.WriteBool(true) || !data.WriteRemoteObject(callerToken)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag and callerToken.");
return INNER_ERR;
}
} else {
if (!data.WriteBool(false)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Failed to write flag.");
return INNER_ERR;
}
}
if (!data.WriteRemoteObject(observer->AsObject())) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "observer write failed.");
return INNER_ERR;

View File

@ -9387,14 +9387,15 @@ int AbilityManagerService::CheckUIExtensionIsFocused(uint32_t uiExtensionTokenId
return ERR_OK;
}
int AbilityManagerService::AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
int AbilityManagerService::AddFreeInstallObserver(const sptr<IRemoteObject> &callerToken,
const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
if (freeInstallManager_ == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "freeInstallManager_ is nullptr.");
return ERR_INVALID_VALUE;
}
return freeInstallManager_->AddFreeInstallObserver(observer);
return freeInstallManager_->AddFreeInstallObserver(callerToken, observer);
}
int32_t AbilityManagerService::IsValidMissionIds(

View File

@ -2704,13 +2704,21 @@ int AbilityManagerStub::FreeInstallAbilityFromRemoteInner(MessageParcel &data, M
int AbilityManagerStub::AddFreeInstallObserverInner(MessageParcel &data, MessageParcel &reply)
{
sptr<IRemoteObject> callerToken = nullptr;
if (data.ReadBool()) {
callerToken = data.ReadRemoteObject();
if (callerToken == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "caller token is nullptr.");
return ERR_INVALID_VALUE;
}
}
sptr<AbilityRuntime::IFreeInstallObserver> observer =
iface_cast<AbilityRuntime::IFreeInstallObserver>(data.ReadRemoteObject());
if (observer == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "observer is nullptr");
return ERR_INVALID_VALUE;
}
int32_t result = AddFreeInstallObserver(observer);
int32_t result = AddFreeInstallObserver(callerToken, observer);
if (!reply.WriteInt32(result)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "reply write failed.");
return ERR_INVALID_VALUE;

View File

@ -21,8 +21,9 @@
namespace OHOS {
namespace AAFwk {
AtomicServiceStatusCallback::AtomicServiceStatusCallback(const std::weak_ptr<FreeInstallManager> &server, bool isAsync)
: server_(server), isAsync_(isAsync)
AtomicServiceStatusCallback::AtomicServiceStatusCallback(
const std::weak_ptr<FreeInstallManager> &server, bool isAsync, int32_t recordId)
: server_(server), isAsync_(isAsync), recordId_(recordId)
{
}
@ -30,21 +31,14 @@ void AtomicServiceStatusCallback::OnInstallFinished(int resultCode, const Want &
{
auto server = server_.lock();
CHECK_POINTER(server);
server->OnInstallFinished(resultCode, want, userId, isAsync_);
server->OnInstallFinished(recordId_, resultCode, want, userId, isAsync_);
}
void AtomicServiceStatusCallback::OnRemoteInstallFinished(int resultCode, const Want &want, int32_t userId)
{
auto server = server_.lock();
CHECK_POINTER(server);
server->OnRemoteInstallFinished(resultCode, want, userId);
}
void AtomicServiceStatusCallback::OnRemoveTimeoutTask(const Want &want)
{
auto server = server_.lock();
CHECK_POINTER(server);
server->OnRemoveTimeoutTask(want);
server->OnRemoteInstallFinished(recordId_, resultCode, want, userId);
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -95,29 +95,6 @@ void AtomicServiceStatusCallbackProxy::OnRemoteInstallFinished(int resultCode, c
}
}
void AtomicServiceStatusCallbackProxy::OnRemoveTimeoutTask(const Want &want)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
if (!data.WriteInterfaceToken(IAtomicServiceStatusCallback::GetDescriptor())) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Write interface token failed.");
return;
}
if (!data.WriteParcelable(&want)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "Write want error.");
return;
}
int32_t error = SendTransactCmd(ON_REMOVE_TIMEOUT_TASK, data, reply, option);
if (error != NO_ERROR) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "OnFinished fail, error: %{public}d", error);
return;
}
}
int32_t AtomicServiceStatusCallbackProxy::SendTransactCmd(uint32_t code, MessageParcel &data,
MessageParcel &reply, MessageOption &option)
{

View File

@ -54,18 +54,6 @@ int AtomicServiceStatusCallbackStub::OnRemoteInstallFinishedInner(MessageParcel
return NO_ERROR;
}
int AtomicServiceStatusCallbackStub::OnRemoveTimeoutTaskInner(MessageParcel &data, MessageParcel &reply)
{
std::unique_ptr<AAFwk::Want> want(data.ReadParcelable<AAFwk::Want>());
if (want == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "AtomicServiceStatusCallbackStub want is nullptr.");
return ERR_INVALID_VALUE;
}
OnRemoveTimeoutTask(*want);
return NO_ERROR;
}
int AtomicServiceStatusCallbackStub::OnRemoteRequest(
uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
{
@ -84,9 +72,6 @@ int AtomicServiceStatusCallbackStub::OnRemoteRequest(
case IAtomicServiceStatusCallbackCmd::ON_REMOTE_FREE_INSTALL_DONE:
return OnRemoteInstallFinishedInner(data, reply);
break;
case IAtomicServiceStatusCallbackCmd::ON_REMOVE_TIMEOUT_TASK:
return OnRemoveTimeoutTaskInner(data, reply);
break;
}
}

View File

@ -28,6 +28,8 @@
#include "hilog_wrapper.h"
#include "hitrace_meter.h"
#include "in_process_call_wrapper.h"
#include "permission_constants.h"
#include "start_ability_utils.h"
#include "utils/app_mgr_util.h"
#include "uri_utils.h"
@ -90,8 +92,7 @@ int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId, int r
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "StartFreeInstall called");
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
if (!isSaCall && !IsTopAbility(callerToken)) {
if (!VerifyStartFreeInstallPermission(callerToken)) {
return NOT_TOP_ABILITY;
}
FreeInstallInfo info = BuildFreeInstallInfo(want, userId, requestCode, callerToken,
@ -100,7 +101,8 @@ int FreeInstallManager::StartFreeInstall(const Want &want, int32_t userId, int r
std::lock_guard<ffrt::mutex> lock(freeInstallListLock_);
freeInstallList_.push_back(info);
}
sptr<AtomicServiceStatusCallback> callback = new AtomicServiceStatusCallback(weak_from_this(), isAsync);
int32_t recordId = GetRecordIdByToken(callerToken);
sptr<AtomicServiceStatusCallback> callback = new AtomicServiceStatusCallback(weak_from_this(), isAsync, recordId);
auto bundleMgrHelper = AbilityUtil::GetBundleManagerHelper();
CHECK_POINTER_AND_RETURN(bundleMgrHelper, GET_ABILITY_SERVICE_FAILED);
AppExecFwk::AbilityInfo abilityInfo = {};
@ -153,7 +155,8 @@ int FreeInstallManager::RemoteFreeInstall(const Want &want, int32_t userId, int
std::lock_guard<ffrt::mutex> lock(freeInstallListLock_);
freeInstallList_.push_back(info);
}
sptr<AtomicServiceStatusCallback> callback = new AtomicServiceStatusCallback(weak_from_this(), false);
int32_t recordId = GetRecordIdByToken(callerToken);
sptr<AtomicServiceStatusCallback> callback = new AtomicServiceStatusCallback(weak_from_this(), false, recordId);
int32_t callerUid = IPCSkeleton::GetCallingUid();
uint32_t accessToken = IPCSkeleton::GetCallingTokenID();
UriUtils::GetInstance().FilterUriWithPermissionDms(info.want, accessToken);
@ -261,7 +264,7 @@ int FreeInstallManager::NotifyDmsCallback(const Want &want, int resultCode)
return reply.ReadInt32();
}
void FreeInstallManager::NotifyFreeInstallResult(const Want &want, int resultCode, bool isAsync)
void FreeInstallManager::NotifyFreeInstallResult(int32_t recordId, const Want &want, int resultCode, bool isAsync)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
std::lock_guard<ffrt::mutex> lock(freeInstallListLock_);
@ -292,12 +295,12 @@ void FreeInstallManager::NotifyFreeInstallResult(const Want &want, int resultCod
}
freeInstallInfo.isFreeInstallFinished = true;
freeInstallInfo.resultCode = resultCode;
HandleFreeInstallResult(freeInstallInfo, resultCode, isAsync);
HandleFreeInstallResult(recordId, freeInstallInfo, resultCode, isAsync);
it = freeInstallList_.erase(it);
}
}
void FreeInstallManager::HandleOnFreeInstallSuccess(FreeInstallInfo &freeInstallInfo, bool isAsync)
void FreeInstallManager::HandleOnFreeInstallSuccess(int32_t recordId, FreeInstallInfo &freeInstallInfo, bool isAsync)
{
TAG_LOGI(AAFwkTag::FREE_INSTALL, "FreeInstall success.");
freeInstallInfo.isInstalled = true;
@ -307,7 +310,7 @@ void FreeInstallManager::HandleOnFreeInstallSuccess(FreeInstallInfo &freeInstall
std::string bundleName = freeInstallInfo.want.GetElement().GetBundleName();
std::string abilityName = freeInstallInfo.want.GetElement().GetAbilityName();
if (freeInstallInfo.isPreStartMissionCalled) {
StartAbilityByPreInstall(freeInstallInfo, bundleName, abilityName, startTime);
StartAbilityByPreInstall(recordId, freeInstallInfo, bundleName, abilityName, startTime);
return;
}
if (freeInstallInfo.isOpenAtomicServiceShortUrl) {
@ -320,7 +323,8 @@ void FreeInstallManager::HandleOnFreeInstallSuccess(FreeInstallInfo &freeInstall
freeInstallInfo.promise->set_value(ERR_OK);
}
void FreeInstallManager::HandleOnFreeInstallFail(FreeInstallInfo &freeInstallInfo, int resultCode, bool isAsync)
void FreeInstallManager::HandleOnFreeInstallFail(int32_t recordId, FreeInstallInfo &freeInstallInfo, int resultCode,
bool isAsync)
{
TAG_LOGI(AAFwkTag::FREE_INSTALL, "FreeInstall failed.");
freeInstallInfo.isInstalled = false;
@ -344,19 +348,20 @@ void FreeInstallManager::HandleOnFreeInstallFail(FreeInstallInfo &freeInstallInf
std::string bundleName = freeInstallInfo.want.GetElement().GetBundleName();
std::string abilityName = freeInstallInfo.want.GetElement().GetAbilityName();
DelayedSingleton<FreeInstallObserverManager>::GetInstance()->OnInstallFinished(
bundleName, abilityName, startTime, resultCode);
recordId, bundleName, abilityName, startTime, resultCode);
return;
}
freeInstallInfo.promise->set_value(resultCode);
}
void FreeInstallManager::HandleFreeInstallResult(FreeInstallInfo &freeInstallInfo, int resultCode, bool isAsync)
void FreeInstallManager::HandleFreeInstallResult(int32_t recordId, FreeInstallInfo &freeInstallInfo, int resultCode,
bool isAsync)
{
if (resultCode == ERR_OK) {
HandleOnFreeInstallSuccess(freeInstallInfo, isAsync);
HandleOnFreeInstallSuccess(recordId, freeInstallInfo, isAsync);
return;
}
HandleOnFreeInstallFail(freeInstallInfo, resultCode, isAsync);
HandleOnFreeInstallFail(recordId, freeInstallInfo, resultCode, isAsync);
}
void FreeInstallManager::StartAbilityByFreeInstall(FreeInstallInfo &info, std::string &bundleName,
@ -374,12 +379,13 @@ void FreeInstallManager::StartAbilityByFreeInstall(FreeInstallInfo &info, std::s
info.callerToken, info.userId, info.requestCode);
}
IPCSkeleton::SetCallingIdentity(identity);
int32_t recordId = GetRecordIdByToken(info.callerToken);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "The result of StartAbility is %{public}d.", result);
DelayedSingleton<FreeInstallObserverManager>::GetInstance()->OnInstallFinished(
bundleName, abilityName, startTime, result);
recordId, bundleName, abilityName, startTime, result);
}
void FreeInstallManager::StartAbilityByPreInstall(FreeInstallInfo &info, std::string &bundleName,
void FreeInstallManager::StartAbilityByPreInstall(int32_t recordId, FreeInstallInfo &info, std::string &bundleName,
std::string &abilityName, std::string &startTime)
{
info.want.SetFlags(info.want.GetFlags() ^ Want::FLAG_INSTALL_ON_DEMAND);
@ -395,7 +401,7 @@ void FreeInstallManager::StartAbilityByPreInstall(FreeInstallInfo &info, std::st
IPCSkeleton::SetCallingIdentity(identity);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "The result of StartAbility is %{public}d.", result);
DelayedSingleton<FreeInstallObserverManager>::GetInstance()->OnInstallFinished(
bundleName, abilityName, startTime, result);
recordId, bundleName, abilityName, startTime, result);
}
void FreeInstallManager::StartAbilityByConvertedWant(FreeInstallInfo &info, const std::string &startTime)
@ -414,7 +420,9 @@ void FreeInstallManager::StartAbilityByConvertedWant(FreeInstallInfo &info, cons
IPCSkeleton::SetCallingIdentity(identity);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "The result of StartAbility is %{public}d.", result);
auto url = info.want.GetUriString();
DelayedSingleton<FreeInstallObserverManager>::GetInstance()->OnInstallFinishedByUrl(startTime, url, result);
int32_t recordId = GetRecordIdByToken(info.callerToken);
DelayedSingleton<FreeInstallObserverManager>::GetInstance()->OnInstallFinishedByUrl(recordId, startTime,
url, result);
}
void FreeInstallManager::StartAbilityByOriginalWant(FreeInstallInfo &info, const std::string &startTime)
@ -426,7 +434,9 @@ void FreeInstallManager::StartAbilityByOriginalWant(FreeInstallInfo &info, const
IPCSkeleton::SetCallingIdentity(identity);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "The result of StartAbility is %{public}d.", result);
auto url = info.want.GetUriString();
DelayedSingleton<FreeInstallObserverManager>::GetInstance()->OnInstallFinishedByUrl(startTime, url, result);
int32_t recordId = GetRecordIdByToken(info.callerToken);
DelayedSingleton<FreeInstallObserverManager>::GetInstance()->OnInstallFinishedByUrl(recordId, startTime,
url, result);
}
int32_t FreeInstallManager::UpdateElementName(Want &want, int32_t userId) const
@ -525,13 +535,14 @@ std::time_t FreeInstallManager::GetTimeStamp()
return timestamp;
}
void FreeInstallManager::OnInstallFinished(int resultCode, const Want &want, int32_t userId, bool isAsync)
void FreeInstallManager::OnInstallFinished(int32_t recordId, int resultCode, const Want &want,
int32_t userId, bool isAsync)
{
HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "%{public}s resultCode = %{public}d", __func__, resultCode);
NotifyDmsCallback(want, resultCode);
NotifyFreeInstallResult(want, resultCode, isAsync);
NotifyFreeInstallResult(recordId, want, resultCode, isAsync);
PostUpgradeAtomicServiceTask(resultCode, want, userId);
}
@ -562,70 +573,24 @@ void FreeInstallManager::PostUpgradeAtomicServiceTask(int resultCode, const Want
}
}
void FreeInstallManager::OnRemoteInstallFinished(int resultCode, const Want &want, int32_t userId)
void FreeInstallManager::OnRemoteInstallFinished(int32_t recordId, int resultCode, const Want &want, int32_t userId)
{
TAG_LOGI(AAFwkTag::FREE_INSTALL, "%{public}s resultCode = %{public}d", __func__, resultCode);
NotifyFreeInstallResult(want, resultCode);
NotifyFreeInstallResult(recordId, want, resultCode);
}
int FreeInstallManager::AddFreeInstallObserver(const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
int FreeInstallManager::AddFreeInstallObserver(const sptr<IRemoteObject> &callerToken,
const sptr<AbilityRuntime::IFreeInstallObserver> &observer)
{
TAG_LOGI(AAFwkTag::FREE_INSTALL, "Add FreeInstallObserver");
return DelayedSingleton<FreeInstallObserverManager>::GetInstance()->AddObserver(observer);
}
void FreeInstallManager::PostTimeoutTask(const Want &want)
{
TAG_LOGI(AAFwkTag::FREE_INSTALL, "PostTimeoutTask begin.");
std::string bundleName = want.GetElement().GetBundleName();
std::string abilityName = want.GetElement().GetAbilityName();
std::string startTime = want.GetStringParam(Want::PARAM_RESV_START_TIME);
auto task = [weak = weak_from_this(), bundleName, abilityName, startTime]() {
auto self = weak.lock();
if (!self) {
TAG_LOGE(AAFwkTag::FREE_INSTALL, "this is nullptr");
return;
}
DelayedSingleton<FreeInstallObserverManager>::GetInstance()->OnInstallFinished(bundleName, abilityName,
startTime, FREE_INSTALL_TIMEOUT);
self->RemoveFreeInstallInfo(bundleName, abilityName, startTime);
};
std::string taskName = std::string("FreeInstallTimeout_") + bundleName + std::string("_") +
abilityName + std::string("_") + startTime;
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
CHECK_POINTER_LOG(handler, "Fail to get AbilityTaskHandler.");
handler->SubmitTask(task, taskName, DELAY_LOCAL_FREE_INSTALL_TIMEOUT);
}
void FreeInstallManager::RemoveTimeoutTask(const std::string &bundleName, const std::string &abilityName,
const std::string &startTime)
{
// remove timeout task
std::string taskName = std::string("FreeInstallTimeout_") + bundleName + std::string("_") +
abilityName + std::string("_") + startTime;
TAG_LOGI(AAFwkTag::FREE_INSTALL, "RemoveTimeoutTask task name:%{public}s", taskName.c_str());
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
CHECK_POINTER_LOG(handler, "Fail to get AbilityTaskHandler.");
handler->CancelTask(taskName);
}
void FreeInstallManager::OnRemoveTimeoutTask(const Want &want)
{
// only SA can call this interface
TAG_LOGI(AAFwkTag::FREE_INSTALL, "OnRemoveTimeoutTask begin.");
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
if (!isSaCall) {
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Permission verification failed.");
return;
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
if (abilityRecord != nullptr) {
return DelayedSingleton<FreeInstallObserverManager>::GetInstance()->AddObserver(abilityRecord->GetRecordId(),
observer);
} else if (AAFwk::PermissionVerification::GetInstance()->IsSACall()) {
return DelayedSingleton<FreeInstallObserverManager>::GetInstance()->AddObserver(-1, observer);
}
std::string bundleName = want.GetElement().GetBundleName();
std::string abilityName = want.GetElement().GetAbilityName();
std::string startTime = want.GetStringParam(Want::PARAM_RESV_START_TIME);
if (bundleName.empty() || abilityName.empty()) {
TAG_LOGE(AAFwkTag::FREE_INSTALL, "wantBundleName or wantAbilityName is empty");
return;
}
RemoveTimeoutTask(bundleName, abilityName, startTime);
return CHECK_PERMISSION_FAILED;
}
void FreeInstallManager::RemoveFreeInstallInfo(const std::string &bundleName, const std::string &abilityName,
@ -730,5 +695,31 @@ int FreeInstallManager::SetAppRunningState(Want &want)
want.SetParam(KEY_IS_APP_RUNNING, isAppRunning);
return ERR_OK;
}
bool FreeInstallManager::VerifyStartFreeInstallPermission(const sptr<IRemoteObject> &callerToken)
{
auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall();
if (isSaCall || IsTopAbility(callerToken)) {
return true;
}
AppExecFwk::AbilityInfo callerInfo;
if (StartAbilityUtils::GetCallerAbilityInfo(callerToken, callerInfo)) {
if (callerInfo.applicationInfo.isSystemApp && AAFwk::PermissionVerification::GetInstance()->
VerifyCallingPermission(PermissionConstants::PERMISSION_START_ABILITIES_FROM_BACKGROUND)) {
return true;
}
}
return false;
}
int32_t FreeInstallManager::GetRecordIdByToken(const sptr<IRemoteObject> &callerToken)
{
auto abilityRecord = Token::GetAbilityRecordByToken(callerToken);
int recordId = -1;
if (abilityRecord != nullptr) {
recordId = abilityRecord->GetRecordId();
}
return recordId;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -31,7 +31,7 @@ FreeInstallObserverManager::FreeInstallObserverManager()
FreeInstallObserverManager::~FreeInstallObserverManager()
{}
int32_t FreeInstallObserverManager::AddObserver(const sptr<IFreeInstallObserver> &observer)
int32_t FreeInstallObserverManager::AddObserver(int32_t recordId, const sptr<IFreeInstallObserver> &observer)
{
TAG_LOGD(AAFwkTag::FREE_INSTALL, "AddObserver begin.");
if (observer == nullptr) {
@ -39,12 +39,8 @@ int32_t FreeInstallObserverManager::AddObserver(const sptr<IFreeInstallObserver>
return ERR_INVALID_VALUE;
}
std::lock_guard<ffrt::mutex> lock(observerLock_);
if (ObserverExistLocked(observer)) {
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Observer exist.");
return ERR_INVALID_VALUE;
}
observerList_.emplace_back(observer);
TAG_LOGD(AAFwkTag::FREE_INSTALL, "observerList_ size:%{public}zu", observerList_.size());
observerMap_[recordId] = observer;
TAG_LOGD(AAFwkTag::FREE_INSTALL, "observerMap_ size:%{public}zu", observerMap_.size());
if (!deathRecipient_) {
std::weak_ptr<FreeInstallObserverManager> thisWeakPtr(shared_from_this());
@ -74,30 +70,28 @@ int32_t FreeInstallObserverManager::RemoveObserver(const sptr<IFreeInstallObserv
return ERR_INVALID_VALUE;
}
std::lock_guard<ffrt::mutex> lock(observerLock_);
auto it = std::find_if(observerList_.begin(), observerList_.end(),
[&observer](const sptr<IFreeInstallObserver> &item) {
return (item && item->AsObject() == observer->AsObject());
});
if (it != observerList_.end()) {
observerList_.erase(it);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "observerList_ size:%{public}zu", observerList_.size());
return ERR_OK;
for (auto &item : observerMap_) {
if (item.second && item.second->AsObject() == observer->AsObject()) {
observerMap_.erase(item.first);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "observerMap_ size:%{public}zu", observerMap_.size());
return ERR_OK;
}
}
TAG_LOGE(AAFwkTag::FREE_INSTALL, "Observer not exist or has been removed.");
return ERR_INVALID_VALUE;
}
void FreeInstallObserverManager::OnInstallFinished(const std::string &bundleName, const std::string &abilityName,
const std::string &startTime, const int &resultCode)
void FreeInstallObserverManager::OnInstallFinished(int32_t recordId, const std::string &bundleName,
const std::string &abilityName, const std::string &startTime, const int &resultCode)
{
auto task = [weak = weak_from_this(), bundleName, abilityName, startTime, resultCode]() {
auto task = [weak = weak_from_this(), recordId, bundleName, abilityName, startTime, resultCode]() {
auto self = weak.lock();
if (self == nullptr) {
TAG_LOGE(AAFwkTag::FREE_INSTALL, "self is nullptr, OnInstallFinished failed.");
return;
}
TAG_LOGI(AAFwkTag::FREE_INSTALL, "OnInstallFinished come.");
self->HandleOnInstallFinished(bundleName, abilityName, startTime, resultCode);
self->HandleOnInstallFinished(recordId, bundleName, abilityName, startTime, resultCode);
};
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
@ -105,17 +99,17 @@ void FreeInstallObserverManager::OnInstallFinished(const std::string &bundleName
handler->SubmitTask(task);
}
void FreeInstallObserverManager::OnInstallFinishedByUrl(const std::string &startTime, const std::string &url,
const int &resultCode)
void FreeInstallObserverManager::OnInstallFinishedByUrl(int32_t recordId, const std::string &startTime,
const std::string &url, const int &resultCode)
{
auto task = [weak = weak_from_this(), startTime, url, resultCode]() {
auto task = [weak = weak_from_this(), recordId, startTime, url, resultCode]() {
auto self = weak.lock();
if (self == nullptr) {
TAG_LOGE(AAFwkTag::FREE_INSTALL, "self is nullptr, OnInstallFinished failed.");
return;
}
TAG_LOGI(AAFwkTag::FREE_INSTALL, "OnInstallFinishedByUrl come.");
self->HandleOnInstallFinishedByUrl(startTime, url, resultCode);
self->HandleOnInstallFinishedByUrl(recordId, startTime, url, resultCode);
};
auto handler = DelayedSingleton<AbilityManagerService>::GetInstance()->GetTaskHandler();
@ -123,44 +117,26 @@ void FreeInstallObserverManager::OnInstallFinishedByUrl(const std::string &start
handler->SubmitTask(task);
}
void FreeInstallObserverManager::HandleOnInstallFinished(const std::string &bundleName, const std::string &abilityName,
const std::string &startTime, const int &resultCode)
void FreeInstallObserverManager::HandleOnInstallFinished(int32_t recordId, const std::string &bundleName,
const std::string &abilityName, const std::string &startTime, const int &resultCode)
{
TAG_LOGD(AAFwkTag::FREE_INSTALL, "HandleOnInstallFinished begin.");
for (auto it = observerList_.begin(); it != observerList_.end(); ++it) {
if ((*it) == nullptr) {
continue;
}
(*it)->OnInstallFinished(bundleName, abilityName, startTime, resultCode);
auto iter = observerMap_.find(recordId);
if (iter != observerMap_.end() && iter->second != nullptr) {
(iter->second)->OnInstallFinished(bundleName, abilityName, startTime, resultCode);
}
}
void FreeInstallObserverManager::HandleOnInstallFinishedByUrl(const std::string &startTime, const std::string &url,
const int &resultCode)
void FreeInstallObserverManager::HandleOnInstallFinishedByUrl(int32_t recordId, const std::string &startTime,
const std::string &url, const int &resultCode)
{
TAG_LOGD(AAFwkTag::FREE_INSTALL, "HandleOnInstallFinishedByUrl begin.");
for (auto it = observerList_.begin(); it != observerList_.end(); ++it) {
if ((*it) == nullptr) {
continue;
}
(*it)->OnInstallFinishedByUrl(startTime, url, resultCode);
auto iter = observerMap_.find(recordId);
if (iter != observerMap_.end() && iter->second != nullptr) {
(iter->second)->OnInstallFinishedByUrl(startTime, url, resultCode);
}
}
bool FreeInstallObserverManager::ObserverExistLocked(const sptr<IFreeInstallObserver> &observer)
{
TAG_LOGD(AAFwkTag::FREE_INSTALL, "ObserExist begin.");
if (observer == nullptr) {
TAG_LOGE(AAFwkTag::FREE_INSTALL, "The param observer is nullptr.");
return false;
}
auto it = std::find_if(observerList_.begin(), observerList_.end(),
[&observer](const sptr<IFreeInstallObserver> &item) {
return (item && item->AsObject() == observer->AsObject());
});
return it != observerList_.end();
}
void FreeInstallObserverManager::OnObserverDied(const wptr<IRemoteObject> &remote)
{
TAG_LOGI(AAFwkTag::FREE_INSTALL, "OnObserverDied begin.");
@ -172,12 +148,12 @@ void FreeInstallObserverManager::OnObserverDied(const wptr<IRemoteObject> &remot
remoteObj->RemoveDeathRecipient(deathRecipient_);
std::lock_guard<ffrt::mutex> lock(observerLock_);
auto it = std::find_if(observerList_.begin(), observerList_.end(), [&remoteObj]
(const sptr<IFreeInstallObserver> item) {
return (item && item->AsObject() == remoteObj);
});
if (it != observerList_.end()) {
observerList_.erase(it);
for (auto &item : observerMap_) {
if (item.second && item.second->AsObject() == remoteObj) {
observerMap_.erase(item.first);
TAG_LOGI(AAFwkTag::FREE_INSTALL, "observerMap_ size:%{public}zu", observerMap_.size());
return;
}
}
}

View File

@ -1153,7 +1153,7 @@ HWTEST_F(AbilityTerminateTest, AaFwk_IAbilityManager_AddFreeInstallObserver_0100
OHOS::DelayedSingleton<AppExecFwk::SysMrgClient>::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID);
sptr<AAFwk::IAbilityManager> abms = iface_cast<AAFwk::IAbilityManager>(remoteObject_);
EXPECT_NE(abms, nullptr);
EXPECT_EQ(0, abms->AddFreeInstallObserver(nullptr));
EXPECT_EQ(0, abms->AddFreeInstallObserver(nullptr, nullptr));
GTEST_LOG_(INFO) << "AaFwk_IAbilityManager_AddFreeInstallObserver_0100";
}

View File

@ -1378,7 +1378,7 @@ HWTEST_F(AbilityManagerClientBranchTest, StartAbilityByCall_002, TestSize.Level1
Want want;
EXPECT_EQ(client_->StartAbilityByCall(want, nullptr), ERR_OK);
client_->EnableRecoverAbility(nullptr);
EXPECT_EQ(client_->AddFreeInstallObserver(nullptr), ERR_OK);
EXPECT_EQ(client_->AddFreeInstallObserver(nullptr, nullptr), ERR_OK);
}
/**

View File

@ -982,10 +982,10 @@ HWTEST_F(AbilityManagerServiceThirdTest, AddFreeInstallObserver_001, TestSize.Le
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest AddFreeInstallObserver_001 start");
auto abilityMs_ = std::make_shared<AbilityManagerService>();
sptr<AbilityRuntime::IFreeInstallObserver> observer;
EXPECT_EQ(abilityMs_->AddFreeInstallObserver(observer), ERR_INVALID_VALUE);
EXPECT_EQ(abilityMs_->AddFreeInstallObserver(nullptr, observer), ERR_INVALID_VALUE);
abilityMs_->freeInstallManager_ = std::make_shared<FreeInstallManager>(abilityMs_);
EXPECT_EQ(abilityMs_->AddFreeInstallObserver(observer), ERR_INVALID_VALUE);
EXPECT_EQ(abilityMs_->AddFreeInstallObserver(nullptr, observer), ERR_INVALID_VALUE);
TAG_LOGI(AAFwkTag::TEST, "AbilityManagerServiceThirdTest AddFreeInstallObserver_001 end");
}

View File

@ -98,7 +98,7 @@ HWTEST_F(FreeInstallTest, FreeInstall_StartFreeInstall_001, TestSize.Level1)
break;
}
}
freeInstallManager_->OnInstallFinished(0, want, userId, false);
freeInstallManager_->OnInstallFinished(-1, 0, want, userId, false);
EXPECT_EQ(res, 0);
}
@ -153,7 +153,7 @@ HWTEST_F(FreeInstallTest, FreeInstall_StartFreeInstall_003, TestSize.Level1)
break;
}
}
freeInstallManager_->OnInstallFinished(1, want, userId, false);
freeInstallManager_->OnInstallFinished(-1, 1, want, userId, false);
EXPECT_EQ(res, 0);
}
@ -177,7 +177,7 @@ HWTEST_F(FreeInstallTest, FreeInstall_OnInstallFinished_001, TestSize.Level1)
FreeInstallInfo info = freeInstallManager_->BuildFreeInstallInfo(want, userId, requestCode, nullptr, false);
freeInstallManager_->freeInstallList_.resize(0);
freeInstallManager_->freeInstallList_.emplace_back(info);
freeInstallManager_->OnInstallFinished(0, want, userId, false);
freeInstallManager_->OnInstallFinished(-1, 0, want, userId, false);
for (auto it = freeInstallManager_->freeInstallList_.begin();
it != freeInstallManager_->freeInstallList_.end(); it++) {
@ -211,7 +211,7 @@ HWTEST_F(FreeInstallTest, FreeInstall_OnInstallFinished_002, TestSize.Level1)
FreeInstallInfo info = freeInstallManager_->BuildFreeInstallInfo(want, userId, requestCode, nullptr, false);
freeInstallManager_->freeInstallList_.resize(0);
freeInstallManager_->freeInstallList_.emplace_back(info);
freeInstallManager_->OnInstallFinished(1, want, userId, false);
freeInstallManager_->OnInstallFinished(-1, 1, want, userId, false);
for (auto it = freeInstallManager_->freeInstallList_.begin();
it != freeInstallManager_->freeInstallList_.end(); it++) {
@ -247,7 +247,7 @@ HWTEST_F(FreeInstallTest, FreeInstall_OnInstallFinished_003, TestSize.Level1)
freeInstallManager_->freeInstallList_.resize(0);
info.promise.reset();
freeInstallManager_->freeInstallList_.emplace_back(info);
freeInstallManager_->OnInstallFinished(0, want, userId, false);
freeInstallManager_->OnInstallFinished(-1, 0, want, userId, false);
int size = freeInstallManager_->freeInstallList_.size();
EXPECT_EQ(size, 1);
@ -291,7 +291,7 @@ HWTEST_F(FreeInstallTest, FreeInstall_OnRemoteInstallFinished_001, TestSize.Leve
FreeInstallInfo info = freeInstallManager_->BuildFreeInstallInfo(want, userId, requestCode, nullptr, false);
freeInstallManager_->freeInstallList_.resize(0);
freeInstallManager_->freeInstallList_.emplace_back(info);
freeInstallManager_->OnRemoteInstallFinished(0, want, userId);
freeInstallManager_->OnRemoteInstallFinished(-1, 0, want, userId);
for (auto it = freeInstallManager_->freeInstallList_.begin();
it != freeInstallManager_->freeInstallList_.end(); it++) {