diff --git a/frameworks/kits/ability/native/BUILD.gn b/frameworks/kits/ability/native/BUILD.gn index 29a8cc3fd1524bb185de8026eaba6040ffc38974..4e914c3226d9c8b788d04ad2a5bf83454d174fc3 100755 --- a/frameworks/kits/ability/native/BUILD.gn +++ b/frameworks/kits/ability/native/BUILD.gn @@ -128,6 +128,8 @@ ohos_shared_library("abilitykit_native") { # "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp", # "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.cpp", # "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.cpp", + "${SUBSYSTEM_DIR}/src/continuation/distributed/ability_distributed_connect_callback_stub.cpp", + "${SUBSYSTEM_DIR}/src/continuation/distributed/ability_distributed_connection.cpp", "${SUBSYSTEM_DIR}/src/continuation/distributed/continuation_handler.cpp", "${SUBSYSTEM_DIR}/src/continuation/distributed/continuation_manager.cpp", "${SUBSYSTEM_DIR}/src/continuation/distributed/continuation_scheduler.cpp", diff --git a/frameworks/kits/ability/native/include/ability.h b/frameworks/kits/ability/native/include/ability.h index d04b3b215c6a065b3115878e50e1793008c05949..b4cfea6aef5c39a6885c4085df0164a855e35bf1 100755 --- a/frameworks/kits/ability/native/include/ability.h +++ b/frameworks/kits/ability/native/include/ability.h @@ -696,16 +696,6 @@ public: */ virtual void SetMainRoute(const std::string &entry) final; - /** - * @brief Migrates this ability to another device on the same distributed network in a reversible way that allows - * this ability to be migrated back to the local device through reverseContinueAbility(). If there are multiple - * candidate devices, a pop-up will be displayed for users to choose the desired one. The ability to migrate and its - * ability slices must implement the IAbilityContinuation interface. Otherwise, an exception is thrown, indicating - * that the ability does not support migration. - * - */ - virtual void ContinueAbilityReversibly() final; - /** * @brief Migrates this ability to the given device on the same distributed network in a reversible way that allows * this ability to be migrated back to the local device through reverseContinueAbility(). The ability to migrate and diff --git a/frameworks/kits/ability/native/include/ability_context.h b/frameworks/kits/ability/native/include/ability_context.h index dbabf9976952a48e5e4c4190f6c04a4c8cdca61b..121de7fe2c2d8826583c37a2af6f816449f69e47 100755 --- a/frameworks/kits/ability/native/include/ability_context.h +++ b/frameworks/kits/ability/native/include/ability_context.h @@ -16,6 +16,8 @@ #ifndef FOUNDATION_APPEXECFWK_OHOS_ABILITY_CONTEXT_H #define FOUNDATION_APPEXECFWK_OHOS_ABILITY_CONTEXT_H +#include + #include "context_container.h" #include "data_ability_helper.h" #include "distributed_sched_interface.h" @@ -722,6 +724,7 @@ protected: std::string callingDeviceId_; std::string callingBundleName_; std::string callingAbilityName_; + std::map, sptr> abilityConnectionMap_; }; } // namespace AppExecFwk diff --git a/frameworks/kits/ability/native/include/continuation/distributed/ability_distributed_connect_callback_stub.h b/frameworks/kits/ability/native/include/continuation/distributed/ability_distributed_connect_callback_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..eb432d3f3390370710b2ceca07989c5419cdbaa8 --- /dev/null +++ b/frameworks/kits/ability/native/include/continuation/distributed/ability_distributed_connect_callback_stub.h @@ -0,0 +1,59 @@ +/* + * 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_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_STUB_H +#define OHOS_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_STUB_H + +#include +#include + +#include "ability_distributed_connection_interface.h" +#include "nocopyable.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class AbilityDistributedConnectionStub + * AbilityDistributeConnect Stub. + */ +class AbilityDistributedConnectionStub : public IRemoteStub { +public: + AbilityDistributedConnectionStub(); + virtual ~AbilityDistributedConnectionStub(); + + virtual int OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + DISALLOW_COPY_AND_MOVE(AbilityDistributedConnectionStub); +}; + +/** + * @class AbilityDistriubuteConnectCallbackRecipient + * AbilityDistriubuteConnectCallbackRecipient notices IRemoteBroker died. + */ +class AbilityDistriubuteConnectCallbackRecipient : public IRemoteObject::DeathRecipient { +public: + using RemoteDiedHandler = std::function &)>; + AbilityDistriubuteConnectCallbackRecipient(RemoteDiedHandler handler); + virtual ~AbilityDistriubuteConnectCallbackRecipient(); + virtual void OnRemoteDied(const wptr &remote); + +private: + RemoteDiedHandler handler_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_STUB_H diff --git a/frameworks/kits/ability/native/include/continuation/distributed/ability_distributed_connection.h b/frameworks/kits/ability/native/include/continuation/distributed/ability_distributed_connection.h new file mode 100644 index 0000000000000000000000000000000000000000..61c2528ae4dd1859d7400d4258958e12f8903029 --- /dev/null +++ b/frameworks/kits/ability/native/include/continuation/distributed/ability_distributed_connection.h @@ -0,0 +1,56 @@ +/* + * 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_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_H +#define OHOS_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_H + +#include "ability_connect_callback_interface.h" +#include "ability_distributed_connect_callback_stub.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class AbilityDistributedConnection + * AbilityDistributeConnect. + */ +class AbilityDistributedConnection : public AbilityDistributedConnectionStub { +public: + AbilityDistributedConnection(const sptr &conn); + ~AbilityDistributedConnection() = default; + + /** + * OnAbilityDistributeConnectDone, AbilityMs notify caller ability the result of connect. + * + * @param element, service ability's ElementName. + * @param remoteObject,.the session proxy of service ability. + * @param resultCode, ERR_OK on success, others on failure. + */ + virtual void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; + + /** + * OnAbilityDistributeDisconnectDone, AbilityMs notify caller ability the result of disconnect. + * + * @param element, service ability's ElementName. + * @param resultCode, ERR_OK on success, others on failure. + */ + virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; + +private: + sptr conn_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_H \ No newline at end of file diff --git a/frameworks/kits/ability/native/include/continuation/distributed/distributed_client.h b/frameworks/kits/ability/native/include/continuation/distributed/distributed_client.h index ce91aeea42e249320547ce8cd3347052b4d0debe..286ccb2cf2f93d2903f577d5eef132c31710e5d2 100644 --- a/frameworks/kits/ability/native/include/continuation/distributed/distributed_client.h +++ b/frameworks/kits/ability/native/include/continuation/distributed/distributed_client.h @@ -42,6 +42,9 @@ public: ErrCode StartRemoteAbility(const Want &want, const AppExecFwk::AbilityInfo &abilityInfo, int32_t requestCode); ErrCode StartContinuation( const Want &want, const AppExecFwk::AbilityInfo &abilityInfo, const sptr &abilityToken); + ErrCode ConnectRemoteAbility( + const Want &want, const AppExecFwk::AbilityInfo &abilityInfo, const sptr &connect); + ErrCode DisconnectRemoteAbility(const sptr &connect); ErrCode NotifyCompleteContinuation( const std::u16string &devId, int32_t sessionId, bool isSuccess, const sptr &reverseScheduler); ErrCode RegisterAbilityToken(const sptr &token, const sptr &appThread); diff --git a/frameworks/kits/ability/native/src/ability.cpp b/frameworks/kits/ability/native/src/ability.cpp index c48beaaf248df49fe1ed6fc99509e68dc2d91088..771b0bdc641bb9a426930b572d3e0d42cd190fe5 100755 --- a/frameworks/kits/ability/native/src/ability.cpp +++ b/frameworks/kits/ability/native/src/ability.cpp @@ -1156,23 +1156,6 @@ void Ability::ContinueAbilityReversibly(const std::string &deviceId) continuationManager_->ContinueAbility(true, deviceId); } -/** - * @brief Migrates this ability to another device on the same distributed network in a reversible way that allows this - * ability to be migrated back to the local device through reverseContinueAbility(). If there are multiple candidate - * devices, a pop-up will be displayed for users to choose the desired one. The ability to migrate and its ability - * slices must implement the IAbilityContinuation interface. Otherwise, an exception is thrown, indicating that the - * ability does not support migration. - * - */ -void Ability::ContinueAbilityReversibly() -{ - if (!VerifySupportForContinuation()) { - APP_LOGE("Ability::ContinueAbilityReversibly failed. VerifySupportForContinuation faled"); - return; - } - continuationManager_->ContinueAbility(true, ""); -} - /** * @brief public final String getOriginalDeviceId​() throws UnsupportedOperationException * Obtains the ID of the source device from which this ability is migrated. @@ -1915,7 +1898,7 @@ void Ability::ProcessFormUpdate(const FormJsInfo &formJsInfo) void Ability::ProcessFormUninstall(const int64_t formId) { APP_LOGI("%{public}s start.", __func__); - // check formId + // check formId if (formId <= 0) { APP_LOGE("%{public}s error, the passed in formId can't be negative or zero.", __func__); return; @@ -1925,8 +1908,7 @@ void Ability::ProcessFormUninstall(const int64_t formId) { std::lock_guard lock(formLock); // get callback iterator by formId - std::map>::iterator appCallbackIterator = - appCallbacks_.find(formId); + std::map>::iterator appCallbackIterator = appCallbacks_.find(formId); // call the callback function when you need to be notified if (appCallbackIterator == appCallbacks_.end()) { @@ -2044,10 +2026,8 @@ bool Ability::DeleteForm(const int64_t formId, const int32_t deleteType) // form lock std::lock_guard lock(formLock); // clean form resource when form is temp form - if (std::find( - lostedByReconnectTempForms_.begin(), - lostedByReconnectTempForms_.end(), - formId) != lostedByReconnectTempForms_.end()) { + if (std::find(lostedByReconnectTempForms_.begin(), lostedByReconnectTempForms_.end(), formId) != + lostedByReconnectTempForms_.end()) { CleanFormResource(formId); // the delete temp form is successfully return true; @@ -2087,7 +2067,7 @@ void Ability::CleanFormResource(const int64_t formId) { APP_LOGI("%{public}s called.", __func__); // compatible with int form id - int64_t cleanId {-1L}; + int64_t cleanId{-1L}; for (auto param : userReqParams_) { uint64_t unsignedFormId = static_cast(formId); uint64_t unsignedParamFirst = static_cast(param.first); @@ -2372,9 +2352,8 @@ void Ability::OnDeathReceived() { std::lock_guard lock(formLock); want = userReqRaram.second; - if (want.GetBoolParam(Constants::PARAM_FORM_TEMPORARY_KEY, false) - && std::find(lostedTempForms.begin(), lostedTempForms.end(), - formId) == lostedTempForms.end()) { + if (want.GetBoolParam(Constants::PARAM_FORM_TEMPORARY_KEY, false) && + std::find(lostedTempForms.begin(), lostedTempForms.end(), formId) == lostedTempForms.end()) { lostedTempForms.emplace_back(formId); continue; } @@ -2430,8 +2409,8 @@ bool Ability::ReAcquireForm(const int64_t formId, const Want &want) // reacquire form FormJsInfo formJsInfo; - if (FormMgr::GetInstance().AddForm(formId, want, formHostClient, formJsInfo) != ERR_OK - || formJsInfo.formId <= 0 || formJsInfo.formId != formId) { + if (FormMgr::GetInstance().AddForm(formId, want, formHostClient, formJsInfo) != ERR_OK || formJsInfo.formId <= 0 || + formJsInfo.formId != formId) { APP_LOGE("%{public}s error, fms reacquire form failed, formId:%{public}" PRId64 ".", __func__, formId); return false; } @@ -2594,8 +2573,10 @@ bool Ability::CheckFormPermission(const std::string &bundleName) const int result = PermissionKit::VerifyPermission(bundleName, Constants::PERMISSION_REQUIRE_FORM, 0); if (result != PermissionState::PERMISSION_GRANTED) { - APP_LOGW("permission = %{public}s, bundleName = %{public}s, result = %{public}d", - Constants::PERMISSION_REQUIRE_FORM.c_str(), bundleName.c_str(), result); + APP_LOGW("permission = %{public}s, bundleName = %{public}s, result = %{public}d", + Constants::PERMISSION_REQUIRE_FORM.c_str(), + bundleName.c_str(), + result); } return result == PermissionState::PERMISSION_GRANTED; } @@ -2764,7 +2745,9 @@ std::shared_ptr Ability::ParsePredictionArgsRe } for (auto iterMap : predicatesBackReferencesMap) { - APP_LOGI("Ability::ParsePredictionArgsReference predicatesBackReferencesMap first:%{public}d second:%{public}d", iterMap.first, iterMap.second); + APP_LOGI("Ability::ParsePredictionArgsReference predicatesBackReferencesMap first:%{public}d second:%{public}d", + iterMap.first, + iterMap.second); int tempCount = ChangeRef2Value(results, numRefs, iterMap.second); if (tempCount < 0) { APP_LOGE("Ability::ParsePredictionArgsReference tempCount:%{public}d", tempCount); @@ -2814,67 +2797,65 @@ std::shared_ptr Ability::ParseValuesBucketReference( continue; } switch (obj.GetType()) { - case NativeRdb::ValueObjectType::TYPE_INT: - { - int val = 0; - if (obj.GetInt(val) != 0) { - APP_LOGE("Ability::ParseValuesBucketReference ValueObject->GetInt() error"); - break; - } - APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutInt(%{public}s, %{public}d)", key.c_str(), val); - retValueBucket.PutInt(key, val); - } - break; - case NativeRdb::ValueObjectType::TYPE_DOUBLE: - { - double val = 0.0; - if (obj.GetDouble(val) != 0) { - APP_LOGE("Ability::ParseValuesBucketReference ValueObject->GetDouble() error"); - break; - } - APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutDouble(%{public}s, %{public}f)", key.c_str(), val); - retValueBucket.PutDouble(key, val); + case NativeRdb::ValueObjectType::TYPE_INT: { + int val = 0; + if (obj.GetInt(val) != 0) { + APP_LOGE("Ability::ParseValuesBucketReference ValueObject->GetInt() error"); + break; } - break; - case NativeRdb::ValueObjectType::TYPE_STRING: - { - std::string val = ""; - if (obj.GetString(val) != 0) { - APP_LOGE("Ability::ParseValuesBucketReference ValueObject->GetString() error"); - break; - } - APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutString(%{public}s, %{public}s)", key.c_str(), val.c_str()); - retValueBucket.PutString(key, val); + APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutInt(%{public}s, %{public}d)", + key.c_str(), + val); + retValueBucket.PutInt(key, val); + } break; + case NativeRdb::ValueObjectType::TYPE_DOUBLE: { + double val = 0.0; + if (obj.GetDouble(val) != 0) { + APP_LOGE("Ability::ParseValuesBucketReference ValueObject->GetDouble() error"); + break; } - break; - case NativeRdb::ValueObjectType::TYPE_BLOB: - { - std::vector val; - if (obj.GetBlob(val) != 0) { - APP_LOGE("Ability::ParseValuesBucketReference ValueObject->GetBlob() error"); - break; - } - APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutBlob(%{public}s, %{public}zu)", key.c_str(), val.size()); - retValueBucket.PutBlob(key, val); + APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutDouble(%{public}s, %{public}f)", + key.c_str(), + val); + retValueBucket.PutDouble(key, val); + } break; + case NativeRdb::ValueObjectType::TYPE_STRING: { + std::string val = ""; + if (obj.GetString(val) != 0) { + APP_LOGE("Ability::ParseValuesBucketReference ValueObject->GetString() error"); + break; } - break; - case NativeRdb::ValueObjectType::TYPE_BOOL: - { - bool val = false; - if (obj.GetBool(val) != 0) { - APP_LOGE("Ability::ParseValuesBucketReference ValueObject->GetBool() error"); - break; - } - APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutBool(%{public}s, %{public}s)", key.c_str(), val ? "true" : "false"); - retValueBucket.PutBool(key, val); + APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutString(%{public}s, %{public}s)", + key.c_str(), + val.c_str()); + retValueBucket.PutString(key, val); + } break; + case NativeRdb::ValueObjectType::TYPE_BLOB: { + std::vector val; + if (obj.GetBlob(val) != 0) { + APP_LOGE("Ability::ParseValuesBucketReference ValueObject->GetBlob() error"); + break; } - break; - default: - { - APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutNull(%{public}s)", key.c_str()); - retValueBucket.PutNull(key); + APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutBlob(%{public}s, %{public}zu)", + key.c_str(), + val.size()); + retValueBucket.PutBlob(key, val); + } break; + case NativeRdb::ValueObjectType::TYPE_BOOL: { + bool val = false; + if (obj.GetBool(val) != 0) { + APP_LOGE("Ability::ParseValuesBucketReference ValueObject->GetBool() error"); + break; } - break; + APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutBool(%{public}s, %{public}s)", + key.c_str(), + val ? "true" : "false"); + retValueBucket.PutBool(key, val); + } break; + default: { + APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutNull(%{public}s)", key.c_str()); + retValueBucket.PutNull(key); + } break; } } diff --git a/frameworks/kits/ability/native/src/ability_context.cpp b/frameworks/kits/ability/native/src/ability_context.cpp index 38fd5442d856a2b4b2dbb0280ec622907d018126..f019febeca7587f87bc62e54750bcc6913f4dc13 100755 --- a/frameworks/kits/ability/native/src/ability_context.cpp +++ b/frameworks/kits/ability/native/src/ability_context.cpp @@ -14,7 +14,9 @@ */ #include "ability_context.h" +#include "ability_distributed_connection.h" #include "ability_manager_client.h" +#include "distributed_client.h" #include "app_log_wrapper.h" #include "resource_manager.h" #include "bundle_constants.h" @@ -236,14 +238,37 @@ bool AbilityContext::ConnectAbility(const Want &want, const sptr abilityInfo = GetAbilityInfo(); + if (abilityInfo == nullptr) { + APP_LOGE("AbilityContext::ConnectAbility info == nullptr"); + return false; + } + if (AppExecFwk::AbilityType::PAGE != type && AppExecFwk::AbilityType::SERVICE != type) { APP_LOGE("AbilityContext::ConnectAbility AbilityType = %{public}d", type); return false; } - APP_LOGI("%{public}s begin ams->ConnectAbility", __func__); - ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, conn, token_); - APP_LOGI("%{public}s end ams->ConnectAbility, ret=%{public}d", __func__, ret); + ErrCode ret = ERR_OK; + if (want.GetOperation().GetDeviceId() == "") { + APP_LOGI("%{public}s begin ams->ConnectAbilityLocal", __func__); + ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, conn, token_); + } else { + APP_LOGI("%{public}s begin ams->ConnectAbilityRemote", __func__); + auto pos = abilityConnectionMap_.find(conn); + if (pos != abilityConnectionMap_.end()) { + APP_LOGI("%{public}s begin ams->ConnectAbilityHasDistributedConnection", __func__); + return false; + } else { + APP_LOGI("%{public}s begin ams->ConnectAbilitySetDistributedConnection", __func__); + sptr distributedConnection = new AbilityDistributedConnection(conn); + abilityConnectionMap_.emplace(conn, distributedConnection); + ret = DistributedClient::GetInstance()->ConnectRemoteAbility(want, *abilityInfo, distributedConnection); + } + } + + APP_LOGI("%{public}s end ConnectAbility, ret=%{public}d", __func__, ret); bool value = ((ret == ERR_OK) ? true : false); if (!value) { APP_LOGE("AbilityContext::ConnectAbility ErrorCode = %{public}d", ret); @@ -254,12 +279,12 @@ bool AbilityContext::ConnectAbility(const Want &want, const sptr &conn) { - APP_LOGD("AbilityContext::DisconnectAbility begin"); + APP_LOGI("%{public}s begin.", __func__); AppExecFwk::AbilityType type = GetAbilityInfoType(); if (AppExecFwk::AbilityType::PAGE != type && AppExecFwk::AbilityType::SERVICE != type) { @@ -267,9 +292,18 @@ void AbilityContext::DisconnectAbility(const sptr &co return; } - APP_LOGI("%{public}s begin ams->DisconnectAbility", __func__); - ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn); - APP_LOGI("%{public}s end ams->ConnectAbility, ret=%{public}d", __func__, ret); + ErrCode ret = ERR_OK; + auto pos = abilityConnectionMap_.find(conn); + if (pos != abilityConnectionMap_.end()) { + APP_LOGI("%{public}s begin ams->DisconnectAbilityRemote", __func__); + ret = DistributedClient::GetInstance()->DisconnectRemoteAbility(pos->second); + abilityConnectionMap_.erase(conn); + } else { + APP_LOGI("%{public}s begin ams->DisconnectAbilityLocal", __func__); + ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(conn); + } + + APP_LOGI("%{public}s end ams->DisconnectAbility, ret=%{public}d", __func__, ret); if (ret != ERR_OK) { APP_LOGE("AbilityContext::DisconnectAbility error"); } @@ -833,7 +867,7 @@ void AbilityContext::AttachBaseContext(const std::shared_ptr &base) ContextContainer::AttachBaseContext(base); APP_LOGI("AbilityContext::AttachBaseContext. End."); } - + /** * @brief Obtains the absolute path to the application-specific cache directory * on the primary external or shared storage device. diff --git a/frameworks/kits/ability/native/src/continuation/distributed/ability_distributed_connect_callback_stub.cpp b/frameworks/kits/ability/native/src/continuation/distributed/ability_distributed_connect_callback_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..482aa0369023be6d8568322f714e4813b1efdcf0 --- /dev/null +++ b/frameworks/kits/ability/native/src/continuation/distributed/ability_distributed_connect_callback_stub.cpp @@ -0,0 +1,89 @@ + +/* + * 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 "ability_distributed_connect_callback_stub.h" + +#include "hilog_wrapper.h" +#include "ipc_types.h" +#include "message_parcel.h" +#include "want.h" + +namespace OHOS { +namespace AAFwk { +AbilityDistributedConnectionStub::AbilityDistributedConnectionStub() +{} + +AbilityDistributedConnectionStub::~AbilityDistributedConnectionStub() +{} + +int AbilityDistributedConnectionStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + std::u16string descriptor = AbilityDistributedConnectionStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + HILOG_INFO("Local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + auto element = data.ReadParcelable(); + switch (code) { + case IAbilityDistributedConnection::ON_ABILITY_DISTRIBUTE_CONNECT_DONE: { + if (element == nullptr) { + HILOG_ERROR("callback stub receive element is nullptr"); + return ERR_INVALID_VALUE; + } + auto remoteObject = data.ReadRemoteObject(); + auto resultCode = data.ReadInt32(); + OnAbilityConnectDone(*element, remoteObject, resultCode); + delete element; + return NO_ERROR; + } + case IAbilityDistributedConnection::ON_ABILITY_DISTRIBUTE_DISCONNECT_DONE: { + if (element == nullptr) { + HILOG_ERROR("callback stub receive element is nullptr"); + return ERR_INVALID_VALUE; + } + auto resultCode = data.ReadInt32(); + OnAbilityDisconnectDone(*element, resultCode); + delete element; + return NO_ERROR; + } + default: { + if (element != nullptr) { + delete element; + } + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } + } +} + +void AbilityDistriubuteConnectCallbackRecipient::OnRemoteDied(const wptr &__attribute__((unused)) remote) +{ + HILOG_ERROR("On remote died."); + if (handler_) { + handler_(remote); + } +} + +AbilityDistriubuteConnectCallbackRecipient::AbilityDistriubuteConnectCallbackRecipient(RemoteDiedHandler handler) + : handler_(handler) +{} + +AbilityDistriubuteConnectCallbackRecipient::~AbilityDistriubuteConnectCallbackRecipient() +{} +} // namespace AAFwk +} // namespace OHOS diff --git a/frameworks/kits/ability/native/src/continuation/distributed/ability_distributed_connection.cpp b/frameworks/kits/ability/native/src/continuation/distributed/ability_distributed_connection.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bef0906c3f190ac6d5ef5b61a8e176d85d222741 --- /dev/null +++ b/frameworks/kits/ability/native/src/continuation/distributed/ability_distributed_connection.cpp @@ -0,0 +1,49 @@ + +/* + * 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 "ability_distributed_connection.h" +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AAFwk { +AbilityDistributedConnection::AbilityDistributedConnection(const sptr &conn) +{ + HILOG_INFO("%{public}s called.", __func__); + conn_ = conn; +} + +void AbilityDistributedConnection::OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) +{ + HILOG_INFO("%{public}s called.", __func__); + if (conn_ == nullptr) { + HILOG_INFO("%{public}s conn_ == nullptr.", __func__); + return; + } + conn_->OnAbilityConnectDone(element, remoteObject, resultCode); +} + +void AbilityDistributedConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) +{ + HILOG_INFO("%{public}s called.", __func__); + if (conn_ == nullptr) { + HILOG_INFO("%{public}s conn_ == nullptr.", __func__); + return; + } + conn_->OnAbilityDisconnectDone(element, resultCode); +} +} // namespace AAFwk +} // namespace OHOS diff --git a/frameworks/kits/ability/native/src/continuation/distributed/distributed_client.cpp b/frameworks/kits/ability/native/src/continuation/distributed/distributed_client.cpp index 3a11fcf6977fcd2ca9a6bb188c1607bb351c761a..6cf085195075d0d1f16dc5c2932aca7ae3ba7139 100755 --- a/frameworks/kits/ability/native/src/continuation/distributed/distributed_client.cpp +++ b/frameworks/kits/ability/native/src/continuation/distributed/distributed_client.cpp @@ -99,6 +99,39 @@ ErrCode DistributedClient::StartContinuation( return dmsProxy_->StartContinuation(want, abilityInfo, abilityToken); } +ErrCode DistributedClient::ConnectRemoteAbility( + const Want &want, const AppExecFwk::AbilityInfo &abilityInfo, const sptr &connect) +{ + APP_LOGI("%{public}s called", __func__); + if (remoteObject_ == nullptr) { + ErrCode err = Connect(); + if (err != ERR_OK) { + return DISTRIBUTED_ABILITY_SERVICE_NOT_CONNECTED; + } + } + if (connect == nullptr) { + return INCOMING_PARAMETER_POINTER_IS_NULL; + } + + return dmsProxy_->ConnectRemoteAbility(want, abilityInfo, connect); +} + +ErrCode DistributedClient::DisconnectRemoteAbility(const sptr &connect) +{ + APP_LOGI("%{public}s called", __func__); + if (remoteObject_ == nullptr) { + ErrCode err = Connect(); + if (err != ERR_OK) { + return DISTRIBUTED_ABILITY_SERVICE_NOT_CONNECTED; + } + } + if (connect == nullptr) { + return INCOMING_PARAMETER_POINTER_IS_NULL; + } + + return dmsProxy_->DisconnectRemoteAbility(connect); +} + ErrCode DistributedClient::NotifyCompleteContinuation( const std::u16string &devId, int32_t sessionId, bool isSuccess, const sptr &reverseScheduler) { diff --git a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager_form.h b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager_form.h index 11a5eefb082ea6884f4d9def0efdbf82de48beb9..9e6f68b68ee7fa9014fa037e66f2423a166c58be 100644 --- a/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager_form.h +++ b/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager_form.h @@ -186,6 +186,63 @@ public: virtual bool GetShortcutInfos(const std::string &bundleName,std::vector &shortcut) override{ return true; } + // /** + // * @brief Starts a shortcut based on the given shortcut ID and bundle name. + // * @param bundleName BundleName Indicates the bundle name of the application to which the shortcut belongs. + // * @param shortcutId Starts a shortcut based on the given shortcut ID and bundle name. + // * @return Returns true if StartShortcut get success + // */ + // virtual bool StartShortcut(const std::string &shortcutId, const std::string &bundleName) override{ + // return true; + // } + /** + * @brief Disables specified home-screen shortcuts that are no longer used. + * @param shortcutIds Indicates the list of shortcut IDs to be disabled. + * @return Returns true if disableHomeShortcuts get success + */ + // virtual bool DisableHomeShortcuts(std::vector &shortcutIds) override{ + // return true; + // } + // /** + // * @brief Enables specified home-screen shortcuts. + // * @param shortcutIds Indicates the list of shortcut IDs to be enabled. + // * @return Returns true if enableHomeShortcuts? get success + // */ + // virtual bool EnableHomeShortcuts(std::vector &shortcutIds) override{ + // return true; + // } + // /** + // * @brief Checks whether a shortcut can be added to the home screen where the application is located. + // * @return Returns true if a shortcut can be added to the home screen; returns false otherwise. + // */ + // virtual bool IsHomeShortcutSupportes() override{ + // return true; + // } + // /** + // * @brief Adds a home-screen shortcut that will be fixed on the home screen. + // * @param shortcutInfo Indicates the ShortcutInfo object containing information about the home-screen shortcut to add. The id, label, and intent attributes of this parameter must be specified. + // * @return Returns true if the shortcut is successfully added; returns false otherwise. + // */ + // virtual bool AddHomeShortcut(ShortcutInfo &shortcutInfo) override{ + // return true; + // } + // /** + // * @brief Updates information about specified home-screen shortcuts that have been added. + // * @param shortcutInfos Updates information about specified home-screen shortcuts that have been added. + // * @return Returns true if the operation is successful; returns false otherwise. + // */ + // virtual bool UpdateShortcuts(std::vector &shortcutInfos) override{ + // return true; + // } + // /** + // * @brief Checks whether a specified shortcut is available. + // * @param shortcutId Indicates the ID of the shortcut to check. + // * @param flag Indicates the type of the shortcut to check. Currently, only the home-screen shortcut IBundleManager#QUERY_SHORTCUT_HOME is available. + // * @return Returns IBundleManager#SHORTCUT_EXISTENCE_EXISTS if the specified shortcut is available; returns IBundleManager#SHORTCUT_EXISTENCE_NOT_EXISTS if it is not available; returns IBundleManager.SHORTCUT_EXISTENCE_UNKNOW if an error occurs. + // */ + // virtual int IsShortcutExist(const std::string &shortcutId, const int &flag) override{ + // return 0; + // } /** * @brief Obtain the HAP module info of a specific ability. * @param abilityInfo Indicates the ability. @@ -232,7 +289,6 @@ public: class BundleMgrService : public BundleMgrStub { public: - ~BundleMgrService() = default; MOCK_METHOD2(GetAppIdByBundleName, std::string(const std::string &bundleName, const int userId)); MOCK_METHOD2(CheckPermission, int(const std::string &bundleName, const std::string &permission)); MOCK_METHOD1(CleanBundleDataFiles, bool(const std::string &bundleName)); @@ -385,6 +441,7 @@ public: virtual bool GetShortcutInfos(const std::string &bundleName,std::vector &shortcut) override{ return true; } + virtual bool GetAllFormsInfo(std::vector &formInfo) override; virtual bool GetFormsInfoByApp(const std::string &bundleName, std::vector &formInfo) override; virtual bool GetFormsInfoByModule( diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp index 32bc3385fb6c2f24c93f2a897d3276df87c6ed0f..2002fe80a666b54468ce666796dbb67b7aff8101 100755 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp @@ -915,7 +915,17 @@ bool WantParams::ReadFromParcelArrayLong(Parcel &parcel, sptr &ao) if (!parcel.ReadInt64Vector(&value)) { return false; } - return SetArray(g_IID_ILong, value, ao); + + #ifdef WANT_PARAM_USE_LONG + return SetArray(g_IID_ILong, value, ao); + #else + std::vector strList; + + for (size_t i=0; i(g_IID_IString, strList, ao); + #endif } bool WantParams::ReadFromParcelArrayFloat(Parcel &parcel, sptr &ao) @@ -1057,7 +1067,11 @@ bool WantParams::ReadFromParcelLong(Parcel &parcel, const std::string &key) { int64_t value; if (parcel.ReadInt64(value)) { - sptr intf = Long::Box(value); + #ifdef WANT_PARAM_USE_LONG + sptr intf = Long::Box(value); + #else + sptr intf = String::Box(std::to_string(value)); + #endif if (intf) { SetParam(key, intf); } diff --git a/frameworks/kits/test/moduletest/cpp/abilitytest/data_ability_helper_module_test.cpp b/frameworks/kits/test/moduletest/cpp/abilitytest/data_ability_helper_module_test.cpp index ef536e3baaa14f8bdb74f3cd975ccabd74cb1cd1..4438b5e5305e5363871ec795b898866491b4a832 100644 --- a/frameworks/kits/test/moduletest/cpp/abilitytest/data_ability_helper_module_test.cpp +++ b/frameworks/kits/test/moduletest/cpp/abilitytest/data_ability_helper_module_test.cpp @@ -240,23 +240,25 @@ HWTEST_F(DataAbilityHelperTest, AaFwk_DataAbilityHelper_OpenFile_Test_0100, Func int fd = dataAbilityHelper->OpenFile(urivalue, mode); EXPECT_NE(fd, -1); - std::string result = "123456"; - FILE *file = nullptr; - file = fdopen(fd, "r"); - EXPECT_NE(file, nullptr); - - if (file != nullptr) { - int strSize = 7; - std::string str(""); - str.resize(strSize); - if (!feof(file)) { - fgets(&str[0], strSize, file); + if (fd > 0) { + std::string result = "123456"; + FILE *file = nullptr; + file = fdopen(fd, "r"); + EXPECT_NE(file, nullptr); + + if (file != nullptr) { + int strSize = 7; + std::string str(""); + str.resize(strSize); + if (!feof(file)) { + fgets(&str[0], strSize, file); + } + string stringstr(str); + EXPECT_STREQ(stringstr.c_str(), result.c_str()); + fclose(file); + system("rm /dataability_openfile_test.txt"); } - string stringstr(str); - EXPECT_STREQ(stringstr.c_str(), result.c_str()); } - fclose(file); - system("rm /dataability_openfile_test.txt"); GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenFile_Test_0100 end"; } @@ -280,23 +282,25 @@ HWTEST_F(DataAbilityHelperTest, AaFwk_DataAbilityHelper_OpenFile_Test_0200, Func int fd = dataAbilityHelper->OpenFile(urivalue, mode); EXPECT_NE(fd, -1); - std::string result = "123456"; - FILE *file = nullptr; - file = fdopen(fd, "r"); - EXPECT_NE(file, nullptr); - - if (file != nullptr) { - int strSize = 7; - std::string str(""); - str.resize(strSize); - if (!feof(file)) { - fgets(&str[0], strSize, file); + if (fd > 0) { + std::string result = "123456"; + FILE *file = nullptr; + file = fdopen(fd, "r"); + EXPECT_NE(file, nullptr); + + if (file != nullptr) { + int strSize = 7; + std::string str(""); + str.resize(strSize); + if (!feof(file)) { + fgets(&str[0], strSize, file); + } + string stringstr(str); + EXPECT_STREQ(stringstr.c_str(), result.c_str()); + fclose(file); + system("rm /dataability_openfile_test.txt"); } - string stringstr(str); - EXPECT_STREQ(stringstr.c_str(), result.c_str()); } - fclose(file); - system("rm /dataability_openfile_test.txt"); GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenFile_Test_0200 end"; } diff --git a/interfaces/innerkits/ability_manager/include/continuation/ability_distributed_connection_interface.h b/interfaces/innerkits/ability_manager/include/continuation/ability_distributed_connection_interface.h new file mode 100644 index 0000000000000000000000000000000000000000..f5a17384fce3801f94f368f53337af29b4fa0c5e --- /dev/null +++ b/interfaces/innerkits/ability_manager/include/continuation/ability_distributed_connection_interface.h @@ -0,0 +1,62 @@ +/* + * 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_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_INTERFACE_H +#define OHOS_AAFWK_ABILITY_DISTRIBUTE_CONNECT_CALLBACK_INTERFACE_H + +#include "want.h" +#include "element_name.h" + +#include "iremote_broker.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class IAbilityDistributedConnection + * IAbilityDistributedConnection is used to notify caller ability that connect or disconnect is complete. + */ +class IAbilityDistributedConnection : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.abilityshell.DistributedConnection"); + + /** + * OnAbilityDistributeConnectDone, AbilityMs notify caller ability the result of connect. + * + * @param element, service ability's ElementName. + * @param remoteObject,.the session proxy of service ability. + * @param resultCode, ERR_OK on success, others on failure. + */ + virtual void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) = 0; + + /** + * OnAbilityDistributeDisconnectDone, AbilityMs notify caller ability the result of disconnect. + * + * @param element, service ability's ElementName. + * @param resultCode, ERR_OK on success, others on failure. + */ + virtual void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) = 0; + + enum { + // ipc id for OnAbilityDistributeConnectDone + ON_ABILITY_DISTRIBUTE_CONNECT_DONE = 0, + + // ipc id for OnAbilityDistributeDisConnectDone + ON_ABILITY_DISTRIBUTE_DISCONNECT_DONE + }; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_AAFWK_ABILITY_CONNECT_CALLBACK_INTERFACE_H diff --git a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp index 59a9208c849e90dd3247c59bc0bbab297b185c14..8bc0572b92ad85c8e44e349bb7675e670acb0b6d 100644 --- a/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp +++ b/interfaces/kits/napi/aafwk/featureAbility/napi_data_ability_helper.cpp @@ -450,6 +450,7 @@ napi_value NAPI_NotifyChange(napi_env env, napi_callback_info info) } ret = WrapVoidToJS(env); } + HILOG_INFO("%{public}s,end", __func__); return ret; } @@ -722,6 +723,11 @@ napi_value RegisterAsync( RegisterExecuteCB, [](napi_env env, napi_status status, void *data) { HILOG_INFO("NAPI_Register, main event thread complete."); + DAHelperOnOffCB *onCB = static_cast(data); + if (onCB != nullptr) { + delete onCB; + onCB = nullptr; + } }, (void *)onCB, &onCB->cbBase.asyncWork)); @@ -886,6 +892,10 @@ void UnRegisterCompleteCB(napi_env env, napi_status status, void *data) DAHelperOnOffCB *offCB = static_cast(data); if (offCB == nullptr || offCB->dataAbilityHelper == nullptr) { HILOG_ERROR("NAPI_UnRegister, param is null."); + if (offCB != nullptr) { + delete offCB; + offCB = nullptr; + } return; } if (offCB->cbBase.cbInfo.callback != nullptr) { @@ -950,6 +960,10 @@ void UnRegisterCompleteCB(napi_env env, napi_status status, void *data) HILOG_ERROR("NAPI_UnRegister, error: uri is null."); } } + if (offCB != nullptr) { + delete offCB; + offCB = nullptr; + } } void NAPIDataAbilityObserver::SetEnv(const napi_env &env) @@ -999,22 +1013,28 @@ void NAPIDataAbilityObserver::OnChange() [](uv_work_t *work, int status) { HILOG_INFO("OnChange, uv_queue_work"); // JS Thread - DAHelperOnOffCB *event = (DAHelperOnOffCB *)work->data; + DAHelperOnOffCB *onCB = (DAHelperOnOffCB *)work->data; napi_value result[ARGS_TWO] = {0}; - result[PARAM0] = GetCallbackErrorValue(event->cbBase.cbInfo.env, NO_ERROR); + result[PARAM0] = GetCallbackErrorValue(onCB->cbBase.cbInfo.env, NO_ERROR); napi_value callback = 0; napi_value undefined = 0; - napi_get_undefined(event->cbBase.cbInfo.env, &undefined); + napi_get_undefined(onCB->cbBase.cbInfo.env, &undefined); napi_value callResult = 0; - napi_get_reference_value(event->cbBase.cbInfo.env, event->cbBase.cbInfo.callback, &callback); + napi_get_reference_value(onCB->cbBase.cbInfo.env, onCB->cbBase.cbInfo.callback, &callback); - napi_call_function(event->cbBase.cbInfo.env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult); - if (event->cbBase.cbInfo.callback != nullptr) { - napi_delete_reference(event->cbBase.cbInfo.env, event->cbBase.cbInfo.callback); + napi_call_function(onCB->cbBase.cbInfo.env, undefined, callback, ARGS_TWO, &result[PARAM0], &callResult); + if (onCB->cbBase.cbInfo.callback != nullptr) { + napi_delete_reference(onCB->cbBase.cbInfo.env, onCB->cbBase.cbInfo.callback); + } + if (onCB != nullptr) { + delete onCB; + onCB = nullptr; + } + if (work != nullptr) { + delete work; + work = nullptr; } - delete event; - delete work; }); if (rev != 0) { if (onCB != nullptr) { diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp index 0b8dd0148ba62bda76bd3a0a4ae193563acdb11e..d70985df33c5632e41710b22e13f6819bbb22064 100755 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_ability.cpp @@ -3148,8 +3148,16 @@ void NAPIAbilityConnection::SetDisconnectCBRef(const napi_ref &ref) void UvWorkOnAbilityConnectDone(uv_work_t *work, int status) { HILOG_INFO("UvWorkOnAbilityConnectDone, uv_queue_work"); + if (work == nullptr) { + HILOG_ERROR("UvWorkOnAbilityConnectDone, work is null"); + return; + } // JS Thread ConnectAbilityCB *connectAbilityCB = static_cast(work->data); + if (connectAbilityCB == nullptr) { + HILOG_ERROR("UvWorkOnAbilityConnectDone, connectAbilityCB is null"); + return; + } napi_value result[ARGS_TWO] = {0}; result[PARAM0] = WrapElementName(connectAbilityCB->cbBase.cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName); @@ -3235,8 +3243,16 @@ void NAPIAbilityConnection::OnAbilityConnectDone( void UvWorkOnAbilityDisconnectDone(uv_work_t *work, int status) { HILOG_INFO("UvWorkOnAbilityDisconnectDone, uv_queue_work"); + if (work == nullptr) { + HILOG_ERROR("UvWorkOnAbilityDisconnectDone, work is null"); + return; + } // JS Thread ConnectAbilityCB *connectAbilityCB = static_cast(work->data); + if (connectAbilityCB == nullptr) { + HILOG_ERROR("UvWorkOnAbilityDisconnectDone, connectAbilityCB is null"); + return; + } napi_value result = nullptr; result = WrapElementName(connectAbilityCB->cbBase.cbInfo.env, connectAbilityCB->abilityConnectionCB.elementName); @@ -3347,13 +3363,17 @@ napi_value NAPI_AcquireDataAbilityHelperCommon(napi_env env, napi_callback_info } napi_value global = nullptr; - NAPI_CALL(env, napi_get_global(env, &global)); + napi_get_global(env, &global); napi_value abilityObj = nullptr; - NAPI_CALL(env, napi_get_named_property(env, global, "ability", &abilityObj)); + napi_get_named_property(env, global, "ability", &abilityObj); Ability *ability = nullptr; - NAPI_CALL(env, napi_get_value_external(env, abilityObj, (void **)&ability)); + napi_get_value_external(env, abilityObj, (void **)&ability); if (ability == nullptr) { HILOG_ERROR("%{public}s, ability == nullptr", __func__); + if (dataAbilityHelperCB != nullptr) { + delete dataAbilityHelperCB; + dataAbilityHelperCB = nullptr; + } return WrapVoidToJS(env); } diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.cpp b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.cpp index 5202568d7141e3a5becc1d561559c12beb24af3a..d3166b17b1641c0fd531351524c3137c9da46c5d 100755 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.cpp +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.cpp @@ -356,6 +356,51 @@ bool UnwrapArrayLongFromJS(napi_env env, napi_value param, std::vector &va return true; } +napi_value WrapArrayInt64ToJS(napi_env env, const std::vector &value) +{ + napi_value jsArray = nullptr; + napi_value jsValue = nullptr; + uint32_t index = 0; + + NAPI_CALL(env, napi_create_array(env, &jsArray)); + for (uint32_t i = 0; i < value.size(); i++) { + jsValue = nullptr; + if (napi_create_int64(env, value[i], &jsValue) == napi_ok) { + if (napi_set_element(env, jsArray, index, jsValue) == napi_ok) { + index++; + } + } + } + return jsArray; +} + +bool UnwrapArrayInt64FromJS(napi_env env, napi_value param, std::vector &value) +{ + uint32_t arraySize = 0; + napi_value jsValue = nullptr; + int64_t natValue = 0; + + if (!IsArrayForNapiValue(env, param, arraySize)) { + return false; + } + + value.clear(); + for (uint32_t i = 0; i < arraySize; i++) { + jsValue = nullptr; + natValue = 0; + if (napi_get_element(env, param, i, &jsValue) != napi_ok) { + return false; + } + + if (!UnwrapInt64FromJS2(env, jsValue, natValue)) { + return false; + } + + value.push_back(natValue); + } + return true; +} + napi_value WrapArrayDoubleToJS(napi_env env, const std::vector &value) { napi_value jsArray = nullptr; @@ -1043,28 +1088,6 @@ void CompletePromiseCallbackWork(napi_env env, napi_status status, void *data) asyncCallbackInfo = nullptr; } -std::vector ConvertStrVector(napi_env env, napi_value value, size_t strMax) -{ - uint32_t arrLen = 0; - napi_get_array_length(env, value, &arrLen); - if (arrLen == 0) { - return {}; - } - std::vector result; - char *buf = new char[strMax + 1]; - size_t len = 0; - for (size_t i = 0; i < arrLen; ++i) { - napi_value element = nullptr; - napi_get_element(env, value, i, &element); - len = 0; - napi_get_value_string_utf8(env, element, buf, strMax, &len); - buf[len] = 0; - result.push_back(buf); - } - delete[] buf; - return result; -} - std::vector ConvertU8Vector(napi_env env, napi_value jsValue) { bool isTypedArray = false; @@ -1089,76 +1112,5 @@ std::vector ConvertU8Vector(napi_env env, napi_value jsValue) return result; } -napi_value ConvertJSValue(napi_env env, std::vector &value) -{ - napi_value jsValue; - napi_status status = napi_create_array_with_length(env, value.size(), &jsValue); - if (status != napi_ok) { - return nullptr; - } - - for (size_t i = 0; i < value.size(); ++i) { - napi_set_element(env, jsValue, i, ConvertJSValue(env, value[i])); - } - return jsValue; -} - -napi_value ConvertJSValue(napi_env env, std::string &value) -{ - napi_value jsValue; - napi_status status = napi_create_string_utf8(env, value.c_str(), value.size(), &jsValue); - if (status != napi_ok) { - return nullptr; - } - return jsValue; -} - -napi_value ConvertJSValue(napi_env env, std::vector &value) -{ - napi_value jsValue = nullptr; - void *native = nullptr; - napi_value buffer = nullptr; - napi_status status = napi_create_arraybuffer(env, value.size(), &native, &buffer); - if (status != napi_ok) { - return nullptr; - } - (void)memcpy_s(native, value.size(), value.data(), value.size()); - status = napi_create_typedarray(env, napi_uint8_array, value.size(), buffer, 0, &jsValue); - if (status != napi_ok) { - return nullptr; - } - return jsValue; -} - -napi_value ConvertJSValue(napi_env env, int32_t value) -{ - napi_value jsValue; - napi_status status = napi_create_int32(env, value, &jsValue); - if (status != napi_ok) { - return nullptr; - } - return jsValue; -} - -napi_value ConvertJSValue(napi_env env, int64_t value) -{ - napi_value jsValue; - napi_status status = napi_create_int64(env, value, &jsValue); - if (status != napi_ok) { - return nullptr; - } - return jsValue; -} - -napi_value ConvertJSValue(napi_env env, double value) -{ - napi_value jsValue; - napi_status status = napi_create_double(env, value, &jsValue); - if (status != napi_ok) { - return nullptr; - } - return jsValue; -} - } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.h b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.h index 2059452a1b8bf478ee8c1588355793bfda5db764..3844f23d4e3f935f8f96f4be2b7181c597fdda94 100755 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.h +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_util.h @@ -64,6 +64,9 @@ bool UnwrapArrayInt32FromJS(napi_env env, napi_value param, std::vector &va napi_value WrapArrayLongToJS(napi_env env, const std::vector &value); bool UnwrapArrayLongFromJS(napi_env env, napi_value param, std::vector &value); +napi_value WrapArrayInt64ToJS(napi_env env, const std::vector &value); +bool UnwrapArrayInt64FromJS(napi_env env, napi_value param, std::vector &value); + napi_value WrapArrayDoubleToJS(napi_env env, const std::vector &value); bool UnwrapArrayDoubleFromJS(napi_env env, napi_value param, std::vector &value); @@ -232,16 +235,8 @@ void CompleteAsyncCallbackWork(napi_env env, napi_status status, void *data); */ void CompletePromiseCallbackWork(napi_env env, napi_status status, void *data); -std::vector ConvertStrVector(napi_env env, napi_value value, size_t strMax); std::vector ConvertU8Vector(napi_env env, napi_value jsValue); -napi_value ConvertJSValue(napi_env env, std::vector &value); -napi_value ConvertJSValue(napi_env env, std::string &value); -napi_value ConvertJSValue(napi_env env, std::vector &value); -napi_value ConvertJSValue(napi_env env, int32_t value); -napi_value ConvertJSValue(napi_env env, int64_t value); -napi_value ConvertJSValue(napi_env env, double value); - } // namespace AppExecFwk } // namespace OHOS #endif // OHOS_APPEXECFWK_NAPI_COMMON_UTIL_H diff --git a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.cpp b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.cpp index 38ee9d504fac42ba2d8642d3dbe8f42893963831..b177bd45f8283898a1ce6abd36bb5fc7f0e5a455 100755 --- a/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.cpp +++ b/interfaces/kits/napi/aafwk/inner/napi_common/napi_common_want.cpp @@ -26,6 +26,7 @@ #include "ohos/aafwk/base/long_wrapper.h" #include "ohos/aafwk/base/short_wrapper.h" #include "ohos/aafwk/base/string_wrapper.h" +#include "ohos/aafwk/base/zchar_wrapper.h" namespace OHOS { namespace AppExecFwk { @@ -97,6 +98,22 @@ bool UnwrapElementName(napi_env env, napi_value param, ElementName &elementName) } return true; } +bool InnerWrapWantParamsChar( + napi_env env, napi_value jsObject, const std::string &key, const AAFwk::WantParams &wantParams) +{ + auto value = wantParams.GetParam(key); + AAFwk::IChar *ao = AAFwk::IChar::Query(value); + if (ao != nullptr) { + std::string natValue(static_cast(ao)->ToString()); + HILOG_INFO("%{public}s called. key=%{public}s, natValue=%{public}s", __func__, key.c_str(), natValue.c_str()); + napi_value jsValue = WrapStringToJS(env, natValue); + if (jsValue != nullptr) { + NAPI_CALL_BASE(env, napi_set_named_property(env, jsObject, key.c_str(), jsValue), false); + return true; + } + } + return false; +} bool InnerWrapWantParamsString( napi_env env, napi_value jsObject, const std::string &key, const AAFwk::WantParams &wantParams) @@ -137,8 +154,8 @@ bool InnerWrapWantParamsByte( auto value = wantParams.GetParam(key); AAFwk::IByte *bo = AAFwk::IByte::Query(value); if (bo != nullptr) { - byte natValue = AAFwk::Byte::Unbox(bo); - napi_value jsValue = WrapInt32ToJS(env, natValue); + int intValue = AAFwk::Byte::Unbox(bo); + napi_value jsValue = WrapInt32ToJS(env, intValue); if (jsValue != nullptr) { NAPI_CALL_BASE(env, napi_set_named_property(env, jsObject, key.c_str(), jsValue), false); return true; @@ -180,14 +197,14 @@ bool InnerWrapWantParamsInt32( return false; } -bool InnerWrapWantParamsLong( +bool InnerWrapWantParamsInt64( napi_env env, napi_value jsObject, const std::string &key, const AAFwk::WantParams &wantParams) { auto value = wantParams.GetParam(key); AAFwk::ILong *ao = AAFwk::ILong::Query(value); if (ao != nullptr) { - long natValue = AAFwk::Long::Unbox(ao); - napi_value jsValue = WrapLongToJS(env, natValue); + int64_t natValue = AAFwk::Long::Unbox(ao); + napi_value jsValue = WrapInt64ToJS(env, natValue); if (jsValue != nullptr) { NAPI_CALL_BASE(env, napi_set_named_property(env, jsObject, key.c_str(), jsValue), false); return true; @@ -244,6 +261,34 @@ bool InnerWrapWantParamsWantParams( } return false; } +bool InnerWrapWantParamsArrayChar(napi_env env, napi_value jsObject, const std::string &key, sptr &ao) +{ + HILOG_INFO("%{public}s called.", __func__); + long size = 0; + if (ao->GetLength(size) != ERR_OK) { + return false; + } + + std::vector natArray; + for (long i = 0; i < size; i++) { + sptr iface = nullptr; + if (ao->Get(i, iface) == ERR_OK) { + AAFwk::IChar *iValue = AAFwk::IChar::Query(iface); + if (iValue != nullptr) { + std::string str(static_cast(iValue)->ToString()); + HILOG_INFO("%{public}s called. str=%{public}s", __func__, str.c_str()); + natArray.push_back(str); + } + } + } + + napi_value jsValue = WrapArrayStringToJS(env, natArray); + if (jsValue != nullptr) { + NAPI_CALL_BASE(env, napi_set_named_property(env, jsObject, key.c_str(), jsValue), false); + return true; + } + return false; +} bool InnerWrapWantParamsArrayString(napi_env env, napi_value jsObject, const std::string &key, sptr &ao) { @@ -322,6 +367,32 @@ bool InnerWrapWantParamsArrayShort(napi_env env, napi_value jsObject, const std: } return false; } +bool InnerWrapWantParamsArrayByte(napi_env env, napi_value jsObject, const std::string &key, sptr &ao) +{ + long size = 0; + if (ao->GetLength(size) != ERR_OK) { + return false; + } + + std::vector natArray; + for (long i = 0; i < size; i++) { + sptr iface = nullptr; + if (ao->Get(i, iface) == ERR_OK) { + AAFwk::IByte *iValue = AAFwk::IByte::Query(iface); + if (iValue != nullptr) { + int intValue = AAFwk::Byte::Unbox(iValue); + natArray.push_back(intValue); + } + } + } + + napi_value jsValue = WrapArrayInt32ToJS(env, natArray); + if (jsValue != nullptr) { + NAPI_CALL_BASE(env, napi_set_named_property(env, jsObject, key.c_str(), jsValue), false); + return true; + } + return false; +} bool InnerWrapWantParamsArrayInt32(napi_env env, napi_value jsObject, const std::string &key, sptr &ao) { @@ -349,14 +420,14 @@ bool InnerWrapWantParamsArrayInt32(napi_env env, napi_value jsObject, const std: return false; } -bool InnerWrapWantParamsArrayLong(napi_env env, napi_value jsObject, const std::string &key, sptr &ao) +bool InnerWrapWantParamsArrayInt64(napi_env env, napi_value jsObject, const std::string &key, sptr &ao) { long size = 0; if (ao->GetLength(size) != ERR_OK) { return false; } - std::vector natArray; + std::vector natArray; for (long i = 0; i < size; i++) { sptr iface = nullptr; if (ao->Get(i, iface) == ERR_OK) { @@ -367,7 +438,7 @@ bool InnerWrapWantParamsArrayLong(napi_env env, napi_value jsObject, const std:: } } - napi_value jsValue = WrapArrayLongToJS(env, natArray); + napi_value jsValue = WrapArrayInt64ToJS(env, natArray); if (jsValue != nullptr) { NAPI_CALL_BASE(env, napi_set_named_property(env, jsObject, key.c_str(), jsValue), false); return true; @@ -429,6 +500,7 @@ bool InnerWrapWantParamsArrayDouble(napi_env env, napi_value jsObject, const std bool InnerWrapWantParamsArray(napi_env env, napi_value jsObject, const std::string &key, sptr &ao) { + HILOG_INFO("%{public}s called. key=%{public}s", __func__, key.c_str()); if (AAFwk::Array::IsStringArray(ao)) { return InnerWrapWantParamsArrayString(env, jsObject, key, ao); } else if (AAFwk::Array::IsBooleanArray(ao)) { @@ -438,13 +510,13 @@ bool InnerWrapWantParamsArray(napi_env env, napi_value jsObject, const std::stri } else if (AAFwk::Array::IsIntegerArray(ao)) { return InnerWrapWantParamsArrayInt32(env, jsObject, key, ao); } else if (AAFwk::Array::IsLongArray(ao)) { - return InnerWrapWantParamsArrayLong(env, jsObject, key, ao); + return InnerWrapWantParamsArrayInt64(env, jsObject, key, ao); } else if (AAFwk::Array::IsFloatArray(ao)) { return InnerWrapWantParamsArrayFloat(env, jsObject, key, ao); } else if (AAFwk::Array::IsByteArray(ao)) { - return InnerWrapWantParamsArrayInt32(env, jsObject, key, ao); + return InnerWrapWantParamsArrayByte(env, jsObject, key, ao); } else if (AAFwk::Array::IsCharArray(ao)) { - return InnerWrapWantParamsArrayString(env, jsObject, key, ao); + return InnerWrapWantParamsArrayChar(env, jsObject, key, ao); } else { return false; } @@ -469,13 +541,13 @@ napi_value WrapWantParams(napi_env env, const AAFwk::WantParams &wantParams) } else if (AAFwk::IInteger::Query(iter->second) != nullptr) { InnerWrapWantParamsInt32(env, jsObject, iter->first, wantParams); } else if (AAFwk::ILong::Query(iter->second) != nullptr) { - InnerWrapWantParamsLong(env, jsObject, iter->first, wantParams); + InnerWrapWantParamsInt64(env, jsObject, iter->first, wantParams); } else if (AAFwk::IFloat::Query(iter->second) != nullptr) { InnerWrapWantParamsFloat(env, jsObject, iter->first, wantParams); } else if (AAFwk::IDouble::Query(iter->second) != nullptr) { InnerWrapWantParamsDouble(env, jsObject, iter->first, wantParams); } else if (AAFwk::IChar::Query(iter->second) != nullptr) { - InnerWrapWantParamsString(env, jsObject, iter->first, wantParams); + InnerWrapWantParamsChar(env, jsObject, iter->first, wantParams); } else if (AAFwk::IByte::Query(iter->second) != nullptr) { InnerWrapWantParamsByte(env, jsObject, iter->first, wantParams); } else if (AAFwk::IArray::Query(iter->second) != nullptr) { diff --git a/sa_profile/182.xml b/sa_profile/182.xml new file mode 100644 index 0000000000000000000000000000000000000000..fe3de304b928019553083259582d67b165135ac8 --- /dev/null +++ b/sa_profile/182.xml @@ -0,0 +1,27 @@ + + + + foundation + + 182 + /system/lib64/libdataobsms.z.so + + + true + false + 1 + + diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn index 666374e66f41541b652bc5386280ab280375f621..018d522a31026761ee375fbec8cfa2ca3efa76c3 100644 --- a/sa_profile/BUILD.gn +++ b/sa_profile/BUILD.gn @@ -14,7 +14,10 @@ import("//build/ohos/sa_profile/sa_profile.gni") ohos_sa_profile("aafwk_sa_profile") { - sources = [ "180.xml" ] + sources = [ + "180.xml", + "182.xml", + ] part_name = "aafwk_standard" } diff --git a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/bundlemgr/mock_bundle_manager.cpp b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/bundlemgr/mock_bundle_manager.cpp index 2b7e1827e886cb1d189510894db7c8fe36b45b0c..e0dd69a1c9132d50ed71cb961866e5cc126ed810 100644 --- a/services/abilitymgr/test/mock/libs/appexecfwk_core/src/bundlemgr/mock_bundle_manager.cpp +++ b/services/abilitymgr/test/mock/libs/appexecfwk_core/src/bundlemgr/mock_bundle_manager.cpp @@ -104,13 +104,11 @@ bool BundleMgrService::QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &ab if (CheckWantEntity(want, abilityInfo)) { return true; } - ElementName elementTemp = want.GetElement(); std::string abilityNameTemp = elementTemp.GetAbilityName(); std::string bundleNameTemp = elementTemp.GetBundleName(); abilityInfo.deviceId = elementTemp.GetDeviceID(); abilityInfo.visible = true; - if (bundleNameTemp.empty() || abilityNameTemp.empty()) { return false; } @@ -132,7 +130,7 @@ bool BundleMgrService::QueryAbilityInfo(const AAFwk::Want &want, AbilityInfo &ab abilityInfo.deviceId = elementTemp.GetDeviceID(); abilityInfo.applicationInfo.bundleName = elementTemp.GetBundleName(); abilityInfo.applicationInfo.name = "hello"; - if (want.HasEntity(Want::ENTITY_HOME) && want.GetAction() == Want::ACTION_HOME) { + if (elementTemp.GetAbilityName().find("com.ohos.launcher.MainAbility") != std::string::npos) { abilityInfo.applicationInfo.isLauncherApp = true; } else { abilityInfo.applicationInfo.isLauncherApp = false; 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 4fef160867bc764e0ba752d72907f50ba3155666..70c42ba74cade5fb14c468ed97482b09731df5d8 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,6 +141,10 @@ void AbilityDumpTest::TearDown() void AbilityDumpTest::StartAbilityes() { + EXPECT_TRUE(g_abilityMs->currentStackManager_); + auto currentTopAbilityRecord = g_abilityMs->currentStackManager_->GetCurrentTopAbility(); + EXPECT_TRUE(currentTopAbilityRecord); + currentTopAbilityRecord->SetAbilityState(AbilityState::ACTIVE); startAbility6(); startAbility1(); startAbility2(); 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 fd4929cded33dec3f539b500556a3b00bba2b64f..e19ca54bad82cdaf781387ee34128594fa0ed9a1 100755 --- 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 @@ -274,7 +274,7 @@ HWTEST_F(AbilityWithApplicationsTest, Teminate_Ability_With_Applications_001, Te } if (topAbility) { - EXPECT_EQ("com.ix.hiworld", topAbility->GetAbilityInfo().applicationName); + EXPECT_EQ("com.ohos.launcher", topAbility->GetAbilityInfo().applicationName); EXPECT_EQ(INACTIVATING, topAbility->GetAbilityState()); } @@ -350,10 +350,10 @@ HWTEST_F(AbilityWithApplicationsTest, Teminate_Ability_With_Applications_002, Te EXPECT_EQ(0, result); auto missionstack = stackmgr->GetCurrentMissionStack(); - EXPECT_EQ(1, missionstack->GetMissionStackId()); + EXPECT_EQ(0, missionstack->GetMissionStackId()); topAbility = missionstack->GetTopAbilityRecord(); EXPECT_TRUE(topAbility != nullptr); - EXPECT_EQ("com.ix.test1", topAbility->GetAbilityInfo().applicationName); + EXPECT_EQ("com.ohos.launcher", topAbility->GetAbilityInfo().applicationName); AbilityRequest request; abilityMs_->GetStackManager()->GetTargetMissionStack(request)->RemoveAll(); GTEST_LOG_(INFO) << "Teminate_Ability_With_Applications_002 end"; 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 240a2899780d78f164165217415c57950e924f8d..91cd0b715e4ad131f523a1823fcc3aa2f3c7e7d6 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 @@ -105,6 +105,7 @@ void AbilityMsAppmsTest::SetUp(void) DelayedSingleton::GetInstance()->Init(callback_); DelayedSingleton::GetInstance()->OnStart(); + WaitUntilTaskFinished(); startAbility(); GTEST_LOG_(INFO) << "SetUp"; } @@ -143,6 +144,10 @@ void AbilityMsAppmsTest::startAbility() ApplicationInfo applicationInfo; auto abilityMs_ = DelayedSingleton::GetInstance(); + EXPECT_TRUE(abilityMs_->currentStackManager_); + auto currentTopAbilityRecord = abilityMs_->currentStackManager_->GetCurrentTopAbility(); + EXPECT_TRUE(currentTopAbilityRecord); + currentTopAbilityRecord->SetAbilityState(AbilityState::ACTIVE); ElementName element("device", "com.ix.hiworld", "luncherAbility"); want.SetElement(element); abilityMs_->StartAbility(want); 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 3b0875dfc5e47522f91627808a08ac52054db38f..965b5ab12a5a5c2584dd50500bb7d0c454c5f964 100755 --- a/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp +++ b/services/abilitymgr/test/unittest/phone/lifecycle_test/lifecycle_test.cpp @@ -126,6 +126,12 @@ void LifecycleTest::TearDown(void) bool LifecycleTest::StartLauncherAbility() { + auto stackManager = aams_->GetStackManager(); + EXPECT_TRUE(stackManager); + auto topAbility = stackManager->GetCurrentTopAbility(); + EXPECT_TRUE(topAbility); + topAbility->SetAbilityState(OHOS::AAFwk::AbilityState::ACTIVE); + ElementName element("device", "com.ix.hiWord", "LauncherAbility"); Want want; want.AddEntity(Want::FLAG_HOME_INTENT_FROM_SYSTEM); @@ -137,8 +143,7 @@ bool LifecycleTest::StartLauncherAbility() GTEST_LOG_(ERROR) << "fail to start Launcher ability"; return false; } - auto stackManager = aams_->GetStackManager(); - EXPECT_TRUE(stackManager); + launcherAbilityRecord_ = (stackManager->GetCurrentTopAbility()); EXPECT_TRUE(launcherAbilityRecord_); if (launcherAbilityRecord_) { diff --git a/tools/zip/include/checked_cast.h b/tools/zip/include/checked_cast.h index 8c67e4c0fb11e3ce87aae93a34f79e0afbd74e8f..76e1cc60eed79e365c896048abafd255910f9db9 100755 --- a/tools/zip/include/checked_cast.h +++ b/tools/zip/include/checked_cast.h @@ -18,6 +18,7 @@ #include #include #include +#include "hilog_wrapper.h" namespace hidden { // workaroud for T& equally matching f(T&) and f(T const&) @@ -88,10 +89,10 @@ struct checked_cast_impl { { #ifdef CHECKED_CAST_SAFE_CONVERSATION T t = dynamic_cast(x); - // check cross cast - if (t != static_cast(x)) + if (t != static_cast(x)) { BAD_CHECKED_CAST(x, T); + } return t; #else return static_cast(x); @@ -104,8 +105,9 @@ struct checked_cast_impl { T t = dynamic_cast(x); // check cross cast - if (t != static_cast(x)) + if (t != static_cast(x)) { BAD_CHECKED_CAST(x, T); + } return t; #else return static_cast(x); @@ -118,12 +120,12 @@ struct checked_cast_impl { static T cast(X &x, hidden::LookUpHelper2 const &) { #ifdef CHECKED_CAST_SAFE_CONVERSATION - T t = dynamic_cast(x); - // check cross cast - if (&t != &static_cast(x)) { - throw std::bad_cast(); - } - return t; + T t = dynamic_cast(x); + // check cross cast + if (&t != &static_cast(x)) { + HILOG_ERROR("!!!bad cast!!!"); + } + return t; #else return static_cast(x); #endif @@ -132,16 +134,12 @@ struct checked_cast_impl { static T cast(X const &x, hidden::LookUpHelper const &) { #ifdef CHECKED_CAST_SAFE_CONVERSATION - try { - T t = dynamic_cast(x); - - // check cross cast - if (&t != &static_cast(x)) - std::bad_cast(); - return t; - } catch (...) { - BAD_CHECKED_CAST(x, T); + T t = dynamic_cast(x); + // check cross cast + if (&t != &static_cast(x)) { + std::bad_cast(); } + return t; #else return static_cast(x); #endif diff --git a/tools/zip/include/zip_reader.h b/tools/zip/include/zip_reader.h index 4f92db6ec0cf809b5d887bfca93595618391bd7f..f2da18cad56c9369c80619c54b8c0c969e79bf69 100755 --- a/tools/zip/include/zip_reader.h +++ b/tools/zip/include/zip_reader.h @@ -53,7 +53,6 @@ public: class ZipReader { public: // A callback that is called when the operation is successful. - // using SuccessCallback = base::OnceClosure; using SuccessCallback = std::function; // A callback that is called when the operation fails. using FailureCallback = std::function; @@ -112,7 +111,14 @@ public: private: FilePath filePath_; int64_t originalSize_ = 0; - struct tm lastModified_; + struct tm lastModified_ { + .tm_year = 0, + .tm_mon = 0, + .tm_mday = 0, + .tm_hour = 0, + .tm_min = 0, + .tm_sec = 0 + }; bool isDirectory_ = false; bool isUnsafe_ = false; bool isEncrypted_ = false; diff --git a/tools/zip/kits/js/@ohos.zlib.d.ts b/tools/zip/kits/js/@ohos.zlib.d.ts index 2fc4a4dec04a17e3e9a40931cddd1565fb05ac05..6fc60c4080d76b941e16e04c55c1e98d04298199 100644 --- a/tools/zip/kits/js/@ohos.zlib.d.ts +++ b/tools/zip/kits/js/@ohos.zlib.d.ts @@ -16,7 +16,7 @@ import { AsyncCallback } from './basic'; declare namespace zlib { - //Zlib library constant definition + // Zlib library constant definition export enum FlushType { FLUSH_TYPE_NO_FLUSH = 0, FLUSH_TYPE_PARTIAL_FLUSH = 1, @@ -42,7 +42,7 @@ declare namespace zlib { ERROR_CODE_VERSION_ERROR = -6 } - //enum CompressLevel + // enum CompressLevel export enum CompressLevel { COMPRESS_LEVEL_NO_COMPRESSION = 0, COMPRESS_LEVEL_BEST_SPEED = 1, @@ -50,7 +50,7 @@ declare namespace zlib { COMPRESS_LEVEL_DEFAULT_COMPRESSION = -1 } - //enum CompressStrategy + // enum CompressStrategy export enum CompressStrategy { COMPRESS_STRATEGY_DEFAULT_STRATEGY = 0, COMPRESS_STRATEGY_FILTERED = 1, @@ -59,34 +59,34 @@ declare namespace zlib { COMPRESS_STRATEGY_FIXED = 4 } - //enum MemLevel + // enum MemLevel export enum MemLevel { MEM_LEVEL_MIN_MEMLEVEL = 1, MEM_LEVEL_DEFAULT_MEMLEVEL = 8, MEM_LEVEL_MAX_MEMLEVEL = 9 } - //zip options + // zip options interface Options { - flush?: FlushType; //corresponding zlib library macro - finishFlush?: FlushType; //corresponding zlib library macro #define Z_FINISH 4 - chunkSize?: number; //Buffer size,>64 - level?: CompressLevel; //Compression level. The compression level is a number from 0 to 9. - //0 has the fastest compression speed (compression process), 9 has the slowest compression speed, + flush?: FlushType; // corresponding zlib library macro + finishFlush?: FlushType; // corresponding zlib library macro #define Z_FINISH 4 + chunkSize?: number; // Buffer size,>64 + level?: CompressLevel; // Compression level. The compression level is a number from 0 to 9. + // 0 has the fastest compression speed (compression process), 9 has the slowest compression speed, // the largest compression rate, and 0 does not compress. - memLevel?: MemLevel; //How much memory should be allocated for the specified internal compression state. + memLevel?: MemLevel; // How much memory should be allocated for the specified internal compression state. // Memlevel = 1 uses the minimum memory, but it is very slow, reducing the compression ratio; Memlevel = 9 uses the maximum memory to get the best speed. The default value is 8. - strategy?: CompressStrategy; //CompressStrategy - dictionary?: ArrayBuffer; //deflate/inflate only, empty dictionary by default + strategy?: CompressStrategy; // CompressStrategy + dictionary?: ArrayBuffer; // deflate/inflate only, empty dictionary by default } - //The interface for compressing the specified file. There is only one callback callback interface + // The interface for compressing the specified file. There is only one callback callback interface function zipFile(inFile:string, outFile:string, options: Options, callback: AsyncCallback): void; function zipFile(inFile:string, outFile:string, options: Options): Promise; - //The interface for decompressing the specified file. There is only one callback callback interface + // The interface for decompressing the specified file. There is only one callback callback interface function unzipFile(inFile:string, outFile:string, options: Options, callback: AsyncCallback): void; function unzipFile(inFile:string, outFile:string, options: Options): Promise; } diff --git a/tools/zip/kits/napi/napi_zlib.cpp b/tools/zip/kits/napi/napi_zlib.cpp index 7f6b765750d3c9da334839a5b5716418095933e3..4e88aceb1fc557afeaa696e5dd7f37573ff9445d 100755 --- a/tools/zip/kits/napi/napi_zlib.cpp +++ b/tools/zip/kits/napi/napi_zlib.cpp @@ -26,9 +26,6 @@ namespace OHOS { namespace AAFwk { namespace LIBZIP { -namespace { -const int E_OK = 0; -} #define NO_ERROR 0 #define COMPRESS_LEVE_CHECK(level, ret) \ @@ -491,10 +488,10 @@ napi_value NAPI_UnzipFile(napi_env env, napi_callback_info info) g_unzipAceCallbackInfo = nullptr; } if (asyncZipCallbackInfo != nullptr) { + napi_delete_async_work(env, asyncZipCallbackInfo->asyncWork); delete asyncZipCallbackInfo; asyncZipCallbackInfo = nullptr; } - } HILOG_INFO("%{public}s,end", __func__); return ret; @@ -684,7 +681,7 @@ void ZipAndUnzipFileAsyncCallBack(std::shared_ptr &zipAceCallb zipAceCallbackInfo.reset(); zipAceCallbackInfo = nullptr; work->data = (void *)asyncCallbackInfo; - int rev = uv_queue_work( + uv_queue_work( loop, work, [](uv_work_t *work) {}, @@ -693,22 +690,19 @@ void ZipAndUnzipFileAsyncCallBack(std::shared_ptr &zipAceCallb ZipAndUnzipFileAsyncCallBackInnerJsThread(work); HILOG_INFO("ZipAndUnzipFileAsyncCallBack, uv_queue_work end."); }); - if (rev != E_OK) { - if (asyncCallbackInfo->isCallBack) { - if (asyncCallbackInfo->callback != nullptr) { - napi_delete_reference(asyncCallbackInfo->env, asyncCallbackInfo->callback); - } - } - if (asyncCallbackInfo != nullptr) { - delete asyncCallbackInfo; - asyncCallbackInfo = nullptr; - } - if (work != nullptr) { - delete work; - work = nullptr; + if (asyncCallbackInfo->isCallBack) { + if (asyncCallbackInfo->callback != nullptr) { + napi_delete_reference(asyncCallbackInfo->env, asyncCallbackInfo->callback); } } - return; + if (asyncCallbackInfo != nullptr) { + delete asyncCallbackInfo; + asyncCallbackInfo = nullptr; + } + if (work != nullptr) { + delete work; + work = nullptr; + } } } // namespace LIBZIP diff --git a/tools/zip/src/zip_internal.cpp b/tools/zip/src/zip_internal.cpp index 3674e6181343cabffa39614363c5d5f1820d661c..34b4258ee8da3c1af84729f26e5fc0587459c360 100755 --- a/tools/zip/src/zip_internal.cpp +++ b/tools/zip/src/zip_internal.cpp @@ -27,7 +27,14 @@ namespace LIBZIP { struct tm GetTmDataFromTickts(int64_t sec) { time_t second = (time_t)sec; - struct tm now; + struct tm now { + .tm_year = 0, + .tm_mon = 0, + .tm_mday = 0, + .tm_hour = 0, + .tm_min = 0, + .tm_sec = 0, + }; struct tm *tmNow = localtime(&second); if (tmNow == nullptr) { return now; @@ -143,9 +150,9 @@ uLong ReadZipBuffer(void *opaque, void *, void *buf, uLong size) // Writes compressed data to the stream. This function always returns zero // because this implementation is only for reading compressed data. -uLong WriteZipBuffer(void *, void *, const void *, uLong) +uLong WriteZipBuffer(void *opaque, void *stream, const void *buf, uLong) { - HILOG_INFO("%{public}s called.", __func__); + HILOG_INFO("%{public}s called. opaque=%p, stream=%p, buf=%p", __func__, opaque, stream, buf); return 0; } @@ -236,8 +243,9 @@ unzFile PrepareMemoryForUnzipping(const std::string &data) return NULL; } ZipBuffer *buffer = static_cast(malloc(sizeof(ZipBuffer))); - if (!buffer) + if (!buffer) { return NULL; + } buffer->data = data.data(); buffer->length = data.length(); buffer->offset = 0; diff --git a/tools/zip/src/zip_writer.cpp b/tools/zip/src/zip_writer.cpp index 777c5510331301901caf2bc16b3445701c40fca2..319685d1acc7edff9fa35ba5c5b1a8101aa687c7 100755 --- a/tools/zip/src/zip_writer.cpp +++ b/tools/zip/src/zip_writer.cpp @@ -197,9 +197,6 @@ bool ZipWriter::FlushEntriesIfNeeded(bool force, const OPTIONS &options, CALLBAC for (auto iter = pendingEntries_.begin(); iter != pendingEntries_.begin() + entry_count; ++iter) { // The FileAccessor requires absolute paths. absolutePaths.push_back(FilePath(rootDir_.Value() + iter->Value())); - - printf("--zip-33--relativePaths=%s--\n", relativePaths[0].Value().c_str()); - printf("--zip-55--absolutePaths=%s--\n", (rootDir_.Value() + iter->Value()).c_str()); } pendingEntries_.erase(pendingEntries_.begin(), pendingEntries_.begin() + entry_count); @@ -211,15 +208,12 @@ bool ZipWriter::FlushEntriesIfNeeded(bool force, const OPTIONS &options, CALLBAC FilePath &relativePath = relativePaths[i]; FilePath &absolutePath = absolutePaths[i]; if (FilePath::PathIsValid(absolutePath)) { - printf("--zip-88--relativePath=%s--\n", relativePath.Value().c_str()); - printf("--zip-99--absolutePath=%s--\n", absolutePath.Value().c_str()); if (!AddFileEntryToZip(zipFile_, relativePath, absolutePath, options)) { CALLING_CALL_BACK(callback, ERROR_CODE_ERRNO) HILOG_INFO("%{public}s called, Failed to write file", __func__); return false; } } else { - printf("--zip-66--\n"); // Missing file or directory case. struct tm *last_modified = GetCurrentSystemTime(); if (!AddDirectoryEntryToZip(zipFile_, relativePath, last_modified, options)) {