From fb0de1774598e68d6b42f889d4cace4110025fd2 Mon Sep 17 00:00:00 2001 From: zhaoyuan17 Date: Tue, 28 Sep 2021 15:26:43 +0800 Subject: [PATCH] aa test Signed-off-by: zhaoyuan17 --- frameworks/kits/ability/native/BUILD.gn | 2 + .../kits/ability/native/include/ability.h | 10 -- .../ability/native/include/ability_context.h | 3 + .../ability_distribute_connect_callback.h | 58 ++++++ ...ability_distribute_connect_callback_stub.h | 59 +++++++ .../distributed/distributed_client.h | 3 + .../kits/ability/native/src/ability.cpp | 165 ++++++++---------- .../ability/native/src/ability_context.cpp | 52 +++++- .../ability/native/src/ability_thread.cpp | 16 -- .../ability_distribute_connect_callback.cpp | 50 ++++++ ...ility_distribute_connect_callback_stub.cpp | 90 ++++++++++ .../distributed/distributed_client.cpp | 33 ++++ ...ty_distribute_connect_callback_interface.h | 62 +++++++ tools/zip/include/checked_cast.h | 33 ++-- tools/zip/include/zip_reader.h | 1 - tools/zip/kits/js/@ohos.zlib.d.ts | 30 ++-- tools/zip/src/zip_internal.cpp | 3 +- tools/zip/src/zip_writer.cpp | 6 - 18 files changed, 503 insertions(+), 173 deletions(-) create mode 100644 frameworks/kits/ability/native/include/continuation/distributed/ability_distribute_connect_callback.h create mode 100644 frameworks/kits/ability/native/include/continuation/distributed/ability_distribute_connect_callback_stub.h create mode 100644 frameworks/kits/ability/native/src/continuation/distributed/ability_distribute_connect_callback.cpp create mode 100644 frameworks/kits/ability/native/src/continuation/distributed/ability_distribute_connect_callback_stub.cpp create mode 100644 interfaces/innerkits/ability_manager/include/continuation/ability_distribute_connect_callback_interface.h diff --git a/frameworks/kits/ability/native/BUILD.gn b/frameworks/kits/ability/native/BUILD.gn index 29a8cc3fd15..dde8bd2d27c 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_distribute_connect_callback.cpp", + "${SUBSYSTEM_DIR}/src/continuation/distributed/ability_distribute_connect_callback_stub.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 d04b3b215c6..b4cfea6aef5 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 dbabf997695..121de7fe2c2 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_distribute_connect_callback.h b/frameworks/kits/ability/native/include/continuation/distributed/ability_distribute_connect_callback.h new file mode 100644 index 00000000000..4e80d264e4b --- /dev/null +++ b/frameworks/kits/ability/native/include/continuation/distributed/ability_distribute_connect_callback.h @@ -0,0 +1,58 @@ +/* + * 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_distribute_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 diff --git a/frameworks/kits/ability/native/include/continuation/distributed/ability_distribute_connect_callback_stub.h b/frameworks/kits/ability/native/include/continuation/distributed/ability_distribute_connect_callback_stub.h new file mode 100644 index 00000000000..2b74b83ecd5 --- /dev/null +++ b/frameworks/kits/ability/native/include/continuation/distributed/ability_distribute_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_distribute_connect_callback_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/distributed_client.h b/frameworks/kits/ability/native/include/continuation/distributed/distributed_client.h index ce91aeea42e..286ccb2cf2f 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 c9da6f9f3d1..cd64ddb4e89 100755 --- a/frameworks/kits/ability/native/src/ability.cpp +++ b/frameworks/kits/ability/native/src/ability.cpp @@ -171,19 +171,6 @@ void Ability::OnStart(const Want &want) abilityInfo_->bundleName.c_str(), abilityInfo_->name.c_str(), winType); - - if (setting_ != nullptr) { - auto windowMode = static_cast( - std::atoi(setting_->GetProperty(AbilityStartSetting::WINDOW_MODE_KEY).c_str())); - APP_LOGI("%{public}s windowMode : %{public}d", __func__, windowMode); - if (windowMode == AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_FLOATING) { - APP_LOGI("%{public}s begin SetWindowMode : WINDOW_MODE_FREE.", __func__); - config->SetWindowType(WINDOW_TYPE_FLOAT); - APP_LOGI("%{public}s end SetWindowMode : WINDOW_MODE_FREE.", __func__); - } - } else { - APP_LOGI("Ability::OnStart setting_ == nullptr."); - } SetUIContent(config); if (abilityWindow_ != nullptr) { @@ -1169,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. @@ -1928,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; @@ -1938,7 +1908,8 @@ 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()) { @@ -2056,8 +2027,10 @@ 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; @@ -2440,8 +2413,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; } @@ -2604,10 +2577,8 @@ 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; } @@ -2776,9 +2747,7 @@ 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); @@ -2828,65 +2797,67 @@ 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; + 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); } - 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_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->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_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->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; + 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->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; + default: + { + APP_LOGI("Ability::ParseValuesBucketReference retValueBucket->PutNull(%{public}s)", key.c_str()); + retValueBucket.PutNull(key); } - 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; + break; } } diff --git a/frameworks/kits/ability/native/src/ability_context.cpp b/frameworks/kits/ability/native/src/ability_context.cpp index 38fd5442d85..6dce911ec96 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_distribute_connect_callback.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"); } diff --git a/frameworks/kits/ability/native/src/ability_thread.cpp b/frameworks/kits/ability/native/src/ability_thread.cpp index 5fd1ef2c143..e08ae0a2e28 100644 --- a/frameworks/kits/ability/native/src/ability_thread.cpp +++ b/frameworks/kits/ability/native/src/ability_thread.cpp @@ -869,22 +869,6 @@ void AbilityThread::NotifyMultiWinModeChanged(int32_t winModeKey, bool flag) return; } - if (flag) { - // true: normal windowMode -> free windowMode - if (winModeKey == MULTI_WINDOW_DISPLAY_FLOATING) { - APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_FREE begin."); - window->SetWindowType(WINDOW_TYPE_FLOAT); - APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_FREE end."); - } else { - APP_LOGI("NotifyMultiWinModeChanged.key:%{public}d", winModeKey); - } - } else { - // false: free windowMode -> normal windowMode - APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_TOP begin."); - window->SetWindowType(WINDOW_TYPE_NORMAL); - APP_LOGI("NotifyMultiWinModeChanged.SetWindowMode:WINDOW_MODE_TOP end."); - } - return; } diff --git a/frameworks/kits/ability/native/src/continuation/distributed/ability_distribute_connect_callback.cpp b/frameworks/kits/ability/native/src/continuation/distributed/ability_distribute_connect_callback.cpp new file mode 100644 index 00000000000..4a32ce8f1c3 --- /dev/null +++ b/frameworks/kits/ability/native/src/continuation/distributed/ability_distribute_connect_callback.cpp @@ -0,0 +1,50 @@ + +/* + * 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_distribute_connect_callback.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/ability_distribute_connect_callback_stub.cpp b/frameworks/kits/ability/native/src/continuation/distributed/ability_distribute_connect_callback_stub.cpp new file mode 100644 index 00000000000..14f4fe3546e --- /dev/null +++ b/frameworks/kits/ability/native/src/continuation/distributed/ability_distribute_connect_callback_stub.cpp @@ -0,0 +1,90 @@ + +/* + * 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_distribute_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/distributed_client.cpp b/frameworks/kits/ability/native/src/continuation/distributed/distributed_client.cpp index 3a11fcf6977..6cf08519507 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/interfaces/innerkits/ability_manager/include/continuation/ability_distribute_connect_callback_interface.h b/interfaces/innerkits/ability_manager/include/continuation/ability_distribute_connect_callback_interface.h new file mode 100644 index 00000000000..f5a17384fce --- /dev/null +++ b/interfaces/innerkits/ability_manager/include/continuation/ability_distribute_connect_callback_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/tools/zip/include/checked_cast.h b/tools/zip/include/checked_cast.h index 8c67e4c0fb1..f44c83374f1 100755 --- a/tools/zip/include/checked_cast.h +++ b/tools/zip/include/checked_cast.h @@ -88,10 +88,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 +104,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 +119,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)) { + throw std::bad_cast(); + } + return t; #else return static_cast(x); #endif @@ -132,16 +133,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 4f92db6ec0c..ef0edfaf68a 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; diff --git a/tools/zip/kits/js/@ohos.zlib.d.ts b/tools/zip/kits/js/@ohos.zlib.d.ts index 2fc4a4dec04..6fc60c4080d 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/src/zip_internal.cpp b/tools/zip/src/zip_internal.cpp index 3674e618134..4833dad7f68 100755 --- a/tools/zip/src/zip_internal.cpp +++ b/tools/zip/src/zip_internal.cpp @@ -236,8 +236,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 777c5510331..319685d1acc 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)) { -- Gitee