From 023862b61e5cf16e58df628f415f7d85549a0d38 Mon Sep 17 00:00:00 2001 From: z30054037 Date: Mon, 13 Nov 2023 11:00:43 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BD=BF=E7=94=A8c++=E6=9D=A5=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2rust=E7=9A=84=E7=9B=B8=E7=AD=89=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E8=BD=AC=E6=88=90=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: z30054037 Change-Id: I68276a776963398b6e372f0ad14e8a77763e0274 --- utils/src/b_error/b_excep_utils.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/utils/src/b_error/b_excep_utils.cpp b/utils/src/b_error/b_excep_utils.cpp index 032f51b34..9af76541f 100644 --- a/utils/src/b_error/b_excep_utils.cpp +++ b/utils/src/b_error/b_excep_utils.cpp @@ -16,6 +16,13 @@ #include "b_error/b_excep_utils.h" #include +#include +#ifdef _WIN32 +#include +#else +#include +#include +#endif #include "b_resources/b_constants.h" #include "cxx.h" @@ -27,11 +34,10 @@ using namespace std; void BExcepUltils::VerifyPath(const string_view &path, bool isExtension) { try { - auto ret = canonicalize(path.data()); - string absPath = ret.c_str(); + string absPath = BExcepUltils::Canonicalize(path); if (isExtension && absPath.find(string(BConstants::PATH_BUNDLE_BACKUP_HOME) - .append(BConstants::SA_BUNDLE_BACKUP_RESTORE)) == std::string::npos) { + .append(BConstants::SA_BUNDLE_BACKUP_RESTORE)) == string::npos) { throw BError(BError::Codes::EXT_INVAL_ARG, "Invalid path, not in backup restore path"); } } catch (const rust::Error &e) { @@ -42,8 +48,21 @@ void BExcepUltils::VerifyPath(const string_view &path, bool isExtension) string BExcepUltils::Canonicalize(const string_view &path) { try { - auto ret = canonicalize(path.data()); - return ret.c_str(); + char full_path[PATH_MAX] = {0}; + //1.转换绝对路径到dir +#ifdef _WIN32 + _fullpath(full_path, path.data(), PATH_MAX); +#else + realpath(path.data(), full_path); +#endif + //2.替换绝对路径中的'\'为'/' + //因为上述方法转换出来的绝对路径之间会以'\'分隔,例如“C:\user\desktop”,字符串处理遇到'\'一般会报错,下面一行代码将'\'全部替换为'/' + // for (int i = 0; full_path[i] != 0 && i < MAX_PATH_LEN; i++) { + // if (full_path[i] == 92) { + // full_path[i] = '/'; + // } + // } + return string(full_path); } catch (const rust::Error &e) { throw BError(BError::Codes::EXT_INVAL_ARG, "Invalid path"); } -- Gitee From f21f2ec67185a088a8baebdeaceb10f1c1ecebe9 Mon Sep 17 00:00:00 2001 From: z30054037 Date: Wed, 15 Nov 2023 08:50:37 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E6=97=B6=E8=B0=83=E7=94=A8=E5=BA=94=E7=94=A8=E5=B8=82=E5=9C=BA?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=A0=E9=80=92=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: z30054037 Change-Id: I01627db24f27bc35f0b4863b87ada94676430fa5 --- BUILD.gn | 6 + services/app_gallery/BUILD.gn | 50 ++++++++ .../include/app_gallery_dispose_proxy.h | 64 ++++++++++ .../include/app_gallery_service_connection.h | 77 ++++++++++++ .../include/i_appgallery_service.h | 44 +++++++ .../src/app_gallery_dispose_proxy.cpp | 117 ++++++++++++++++++ services/backup_sa/BUILD.gn | 1 + .../src/module_ipc/service_reverse_proxy.cpp | 7 ++ 8 files changed, 366 insertions(+) create mode 100644 services/app_gallery/BUILD.gn create mode 100644 services/app_gallery/include/app_gallery_dispose_proxy.h create mode 100644 services/app_gallery/include/app_gallery_service_connection.h create mode 100644 services/app_gallery/include/i_appgallery_service.h create mode 100644 services/app_gallery/src/app_gallery_dispose_proxy.cpp diff --git a/BUILD.gn b/BUILD.gn index 1b6471490..53c3ae9b1 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -49,3 +49,9 @@ group("tgt_backup_tests") { "tests/unittests", ] } + +group("tgt_app_gallery") { + deps = [ + "services/app_gallery", + ] +} diff --git a/services/app_gallery/BUILD.gn b/services/app_gallery/BUILD.gn new file mode 100644 index 000000000..0d87934a7 --- /dev/null +++ b/services/app_gallery/BUILD.gn @@ -0,0 +1,50 @@ +# Copyright (c) Huawei Device Co., Ltd. 2023. +# 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. + +import("//build/ohos.gni") +import("//foundation/filemanagement/app_file_service/backup.gni") + +ohos_shared_library("app_gallery") { + sources = [ + "src/app_gallery_dispose_proxy.cpp", + ] + + defines = [ + "LOG_DOMAIN=0xD004311", + "LOG_TAG=\"AppGallery\"", + ] + + include_dirs = [ "include" ] + + deps = [ + "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", + "${path_backup}/utils:backup_utils", + "${path_jsoncpp}:jsoncpp", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "access_token:libaccesstoken_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] + + use_exceptions = true + part_name = "app_file_service" + subsystem_name = "filemanagement" +} \ No newline at end of file diff --git a/services/app_gallery/include/app_gallery_dispose_proxy.h b/services/app_gallery/include/app_gallery_dispose_proxy.h new file mode 100644 index 000000000..5163b908f --- /dev/null +++ b/services/app_gallery/include/app_gallery_dispose_proxy.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) Huawei Device Co., Ltd. 2023. + * 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_FILEMGMT_BACKUP_APP_GALLERY_DISPOSE_PROXY_H +#define OHOS_FILEMGMT_BACKUP_APP_GALLERY_DISPOSE_PROXY_H + +#include +#include + +#include + +#include "i_appgallery_service.h" + +namespace OHOS::FileManagement::Backup { +enum class DisposeErr { + OK = 0, + CONN_FAIL = 1, + IPC_FAIL = 2, + REQUEST_FAIL = 3, +}; + +class AppGalleryDisposeProxy : public IRemoteStub { +public: + DISALLOW_COPY_AND_MOVE(AppGalleryDisposeProxy); + + AppGalleryDisposeProxy(); + ~AppGalleryDisposeProxy(); + + static sptr GetInstance(); + + DisposeErr StartBackup(const std::string &bundleName); + DisposeErr EndBackup(const std::string &bundleName); + DisposeErr StartRestore(const std::string &bundleName); + DisposeErr EndRestore(const std::string &bundleName); + + static std::condition_variable conditionVal_; + static std::string abilityName; + static std::mutex appRemoteObjLock_; + static std::mutex conditionVal_; + static sptr appRemoteObj_; + +private: + DisposeErr DoDispose(const std::string &bundleName, DisposeOperation disposeOperation); + +private: + static std::mutex instanceLock_; + static std::mutex conditionMutex_; + static sptr appGalleryDisposeProxyInstance_; +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_APP_GALLERY_DISPOSE_PROXY_H \ No newline at end of file diff --git a/services/app_gallery/include/app_gallery_service_connection.h b/services/app_gallery/include/app_gallery_service_connection.h new file mode 100644 index 000000000..41a04af23 --- /dev/null +++ b/services/app_gallery/include/app_gallery_service_connection.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) Huawei Device Co., Ltd. 2023. + * 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_FILEMGMT_BACKUP_APP_GALLERY_SERVICE_CONNECTION_H +#define OHOS_FILEMGMT_BACKUP_APP_GALLERY_SERVICE_CONNECTION_H + +#include +#include + +#include "ability_manager_client.h" +#include "ability_connect_callback_stub.h" +#include "want.h" + +#include "i_appgallery_service.h" +#include "filemgmt_libhilog.h" + +namespace OHOS::FileManagement::Backup { +using namespace OHOS::AppExecFwk; +const std::string APP_GALLERY_PKG_NAME = "com.huawei.hmsapp.appgallery"; +const int32_t CONNECT_TIME = 5; + +template class AppGralleryConnection : public AbilityConnectionStub { +public: + void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr &remoteObject, + int resultCode) + { + std::string uri = element.GetURI(); + HILOGI("OnAbilityConnectDone, uri = %{public}s", uri.c_str()); + T::appRemoteObj_ = remoteObject; + T::conditionVal_.notify_one(); + } + + void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) + { + std::string uri = element.GetURI(); + HILOGI("OnAbilityDisconnectDone, uri = %{public}s", uri.c_str()); + T::appRemoteObj_ = nullptr; + } +}; + +template bool ConnectExtAbility() +{ + HILOGI("ConnectExtAbility called"); + std::lock_guard autoLock(T::appRemoteObjLock_); + if (T::appRemoteObj_ != nullptr) { + return true; + } + + Want want; + want.SetElementName(APP_GALLERY_PKG_NAME, T::abilityName); + sptr connect = new AppGralleryConnection(); + auto ret = AbilityManagerClient::GetInstance()->ConnectAbility(want, connect, -1); + + std::unique_lock uniqueLock(T::connectMutex); + T::conditionVal_.wait_for(uniqueLock, std::chrono::seconds(CONNECT_TIME)); + if (ret != IAppGalleryService::ERR_OK || T::appRemoteObj_ == nullptr) { + HILOGI("ConnectExtAbility failed, ret=%{public}d", ret); + T::appRemoteObj_ = nullptr; + return false; + } + HILOGI("ConnectExtAbility success, ret=%{public}d", ret); + return true; +}; +} // namespace OHOS::FileManagement::Backup +#endif // OHOS_FILEMGMT_BACKUP_APP_GALLERY_SERVICE_CONNECTION_H \ No newline at end of file diff --git a/services/app_gallery/include/i_appgallery_service.h b/services/app_gallery/include/i_appgallery_service.h new file mode 100644 index 000000000..fdff003f0 --- /dev/null +++ b/services/app_gallery/include/i_appgallery_service.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) Huawei Device Co., Ltd. 2023. + * 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_FILEMGMT_BACKUP_I_APP_GALLERY_SERVICE_H +#define OHOS_FILEMGMT_BACKUP_I_APP_GALLERY_SERVICE_H + +#include + +#include "iremote_proxy.h" + +namespace OHOS::FileManagement::Backup { +class IAppGalleryService: public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.FileManagement.Backup.IAppGalleryService"); + + enum class DisposeOperation { + START_RESTORE = 3, + END_RESTORE = 4, + START_BACKUP = 5, + END_BACKUP = 6, + }; + + enum Errcode { + ERR_BASE = (-99), + ERR_FAILED = (-1), + ERR_PERMISSION_DENIED = (-2), + ERR_OK = 0, + }; +}; +} // namespace OHOS::FileManagement::Backup + +#endif // OHOS_FILEMGMT_BACKUP_I_APP_GALLERY_SERVICE_H \ No newline at end of file diff --git a/services/app_gallery/src/app_gallery_dispose_proxy.cpp b/services/app_gallery/src/app_gallery_dispose_proxy.cpp new file mode 100644 index 000000000..69422cae9 --- /dev/null +++ b/services/app_gallery/src/app_gallery_dispose_proxy.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) Huawei Device Co., Ltd. 2023. + * 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 + +#include "message_parcel.h" +#include "message_opetion.h" +#include "nlohmann/json.hpp" +#include "want.h" + +#include "app_gallery_dispose_proxy.h" +#include "app_gallery_service_connection.h" +#include "filemgmt_libhilog.h" + +namespace OHOS::FileManagement::Backup { +using namespace std; + +mutex AppGalleryDisposeProxy::instanceLock_; +mutex AppGalleryDisposeProxy::conditionMutex_; + +string AppGalleryDisposeProxy::abilityName = "AppFoundationServiceExtensionAbility"; +sptr AppGalleryDisposeProxy::appRemoteObj_; +condition_variable AppGalleryDisposeProxy::conditionVal_; +mutex AppGalleryDisposeProxy::appRemoteObjLock_; +mutex AppGalleryDisposeProxy::connectMutex; +sptr AppGalleryDisposeProxy::appGalleryDisposeProxyInstance_; + +AppGalleryDisposeProxy::AppGalleryDisposeProxy() +{ + HILOGI("AppGalleryDisposeProxy constructor"); +} + +AppGalleryDisposeProxy::~AppGalleryDisposeProxy() +{ + HILOGI("AppGalleryDisposeProxy destructor"); +} + +sptr AppGalleryDisposeProxy::GetInstance() +{ + if (appGalleryDisposeProxyInstance_ == nullptr) { + lock_guard autoLock(instanceLock_); + if (appGalleryDisposeProxyInstance_ == nullptr) { + appGalleryDisposeProxyInstance_ = new AppGalleryDisposeProxy; + } + } + + return appGalleryDisposeProxyInstance_; +} + +DisposeErr AppGalleryDisposeProxy::StartBackup(const std::string &bundleName) +{ + HILOGI("StartBackup, app %{public}s", bundleName.c_str()); + return DoDispose(bundleName, DisposeOperation::START_BACKUP); +} + +DisposeErr AppGalleryDisposeProxy::EndBackup(const std::string &bundleName) +{ + HILOGI("EndBackup, app %{public}s", bundleName.c_str()); + return DoDispose(bundleName, DisposeOperation::END_BACKUP); +} + +DisposeErr AppGalleryDisposeProxy::StartRestore(const std::string &bundleName) +{ + HILOGI("StartRestore, app %{public}s", bundleName.c_str()); + return DoDispose(bundleName, DisposeOperation::START_RESTORE); +} + +DisposeErr AppGalleryDisposeProxy::EndRestore(const std::string &bundleName) +{ + HILOGI("EndRestore, app %{public}s", bundleName.c_str()); + return DoDispose(bundleName, DisposeOperation::END_RESTORE); +} + +DisposeErr AppGalleryDisposeProxy::DoDispose(const std::string &bundleName, DisposeOperation disposeOperation) +{ + HILOGI("DoDispose, app %{public}s, operation %{public}d", bundleName.c_str(), disposeOperation); + if (!ConnectExtAbility() || appRemoteObj_ == nullptr) { + HILOGI("Can not connect to %{public}s", bundleName.c_str()); + return DisposeErr::CONN_FAIL; + } + + MessageParcel data; + if (!data.WriteString16(Str8ToStr16(bundleName))) { + HILOGI("write ownerInfo and bundleName failed"); + return DisposeErr::IPC_FAIL; + } + + if (!data.WriteRemoteObject(this)) { + HILOGI("write RemoteObject failed"); + return DisposeErr::IPC_FAIL; + } + + MessageParcel reply; + MessageOption option(MessageOption::TF_ASYNC); + auto ret = appRemoteObj_->SendRequest(static_cast(disposeOperation), data, reply, option); + if (ret != ERR_NONE) { + HILOGI("SendRequest error, code=%{public}d, bundleName=%{public}s", disposeOperation, bundleName.c_str()); + return DisposeErr::REQUEST_FAIL; + } + + HILOGI("SendRequest error, code=%{public}d, bundleName=%{public}s", disposeOperation, bundleName.c_str()); + return DisposeErr::OK; +} + +} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index d589c50d6..2f4f6a9fb 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -39,6 +39,7 @@ ohos_shared_library("backup_sa") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/utils:backup_utils", + "${path_backup}/services/app_gallery:app_gallery", "${path_jsoncpp}:jsoncpp", ] diff --git a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp index 6dd0e4100..ed8aa156e 100644 --- a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp +++ b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp @@ -15,6 +15,7 @@ #include "module_ipc/service_reverse_proxy.h" +#include "app_gallery_dispose_proxy.h" #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" #include "filemgmt_libhilog.h" @@ -114,6 +115,9 @@ void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleN err != ERR_OK) { throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); } + + DisposeErr disposeErr = AppGalleryDisposeProxy::StartRestore(bundleName); + HILOGI("AppGalleryDisposeProxy StartRestore, code=%{public}d, bundleName=%{public}s", disposeOperation, bundleName.c_str()); } void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName) @@ -133,6 +137,9 @@ void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundle err != ERR_OK) { throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); } + + DisposeErr disposeErr = AppGalleryDisposeProxy::EndRestore(bundleName); + HILOGI("AppGalleryDisposeProxy EndRestore, code=%{public}d, bundleName=%{public}s", disposeOperation, bundleName.c_str()); } void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) -- Gitee From 36b9ab5b3341f321d4ecafc43d1ab3fa6340f8ad Mon Sep 17 00:00:00 2001 From: z30054037 Date: Thu, 16 Nov 2023 05:57:40 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=9C=A8=E6=81=A2=E5=A4=8D=E6=97=B6=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=BA=94=E7=94=A8=E5=B8=82=E5=9C=BA=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=BC=A0=E9=80=92=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: z30054037 Change-Id: I41c3e7bab0982182abe4fdf869cf740983dda42e --- BUILD.gn | 8 +-- services/app_gallery/BUILD.gn | 50 ------------------- services/backup_sa/BUILD.gn | 2 +- .../app_gallery_dispose_proxy.h | 2 +- .../app_gallery_service_connection.h | 1 + .../i_appgallery_service.h | 0 .../app_gallery_dispose_proxy.cpp | 5 +- .../src/module_ipc/service_reverse_proxy.cpp | 13 ++--- 8 files changed, 13 insertions(+), 68 deletions(-) delete mode 100644 services/app_gallery/BUILD.gn rename services/{app_gallery/include => backup_sa/include/module_app_gallery}/app_gallery_dispose_proxy.h (98%) rename services/{app_gallery/include => backup_sa/include/module_app_gallery}/app_gallery_service_connection.h (99%) rename services/{app_gallery/include => backup_sa/include/module_app_gallery}/i_appgallery_service.h (100%) rename services/{app_gallery/src => backup_sa/src/module_app_gallery}/app_gallery_dispose_proxy.cpp (97%) diff --git a/BUILD.gn b/BUILD.gn index 53c3ae9b1..5729edd6c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -48,10 +48,4 @@ group("tgt_backup_tests") { "tests/moduletests", "tests/unittests", ] -} - -group("tgt_app_gallery") { - deps = [ - "services/app_gallery", - ] -} +} \ No newline at end of file diff --git a/services/app_gallery/BUILD.gn b/services/app_gallery/BUILD.gn deleted file mode 100644 index 0d87934a7..000000000 --- a/services/app_gallery/BUILD.gn +++ /dev/null @@ -1,50 +0,0 @@ -# Copyright (c) Huawei Device Co., Ltd. 2023. -# 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. - -import("//build/ohos.gni") -import("//foundation/filemanagement/app_file_service/backup.gni") - -ohos_shared_library("app_gallery") { - sources = [ - "src/app_gallery_dispose_proxy.cpp", - ] - - defines = [ - "LOG_DOMAIN=0xD004311", - "LOG_TAG=\"AppGallery\"", - ] - - include_dirs = [ "include" ] - - deps = [ - "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", - "${path_backup}/utils:backup_utils", - "${path_jsoncpp}:jsoncpp", - ] - - external_deps = [ - "ability_base:want", - "ability_runtime:ability_manager", - "access_token:libaccesstoken_sdk", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - ] - - use_exceptions = true - part_name = "app_file_service" - subsystem_name = "filemanagement" -} \ No newline at end of file diff --git a/services/backup_sa/BUILD.gn b/services/backup_sa/BUILD.gn index 2f4f6a9fb..cf8de03ca 100644 --- a/services/backup_sa/BUILD.gn +++ b/services/backup_sa/BUILD.gn @@ -16,6 +16,7 @@ import("//foundation/filemanagement/app_file_service/backup.gni") ohos_shared_library("backup_sa") { sources = [ + "src/module_app_gallery/app_gallery_dispose_proxy.cpp", "src/module_external/bms_adapter.cpp", "src/module_external/inner_receiver_impl.cpp", "src/module_external/sms_adapter.cpp", @@ -39,7 +40,6 @@ ohos_shared_library("backup_sa") { deps = [ "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", "${path_backup}/utils:backup_utils", - "${path_backup}/services/app_gallery:app_gallery", "${path_jsoncpp}:jsoncpp", ] diff --git a/services/app_gallery/include/app_gallery_dispose_proxy.h b/services/backup_sa/include/module_app_gallery/app_gallery_dispose_proxy.h similarity index 98% rename from services/app_gallery/include/app_gallery_dispose_proxy.h rename to services/backup_sa/include/module_app_gallery/app_gallery_dispose_proxy.h index 5163b908f..bebbf578a 100644 --- a/services/app_gallery/include/app_gallery_dispose_proxy.h +++ b/services/backup_sa/include/module_app_gallery/app_gallery_dispose_proxy.h @@ -48,7 +48,7 @@ public: static std::condition_variable conditionVal_; static std::string abilityName; static std::mutex appRemoteObjLock_; - static std::mutex conditionVal_; + static std::mutex connectMutex; static sptr appRemoteObj_; private: diff --git a/services/app_gallery/include/app_gallery_service_connection.h b/services/backup_sa/include/module_app_gallery/app_gallery_service_connection.h similarity index 99% rename from services/app_gallery/include/app_gallery_service_connection.h rename to services/backup_sa/include/module_app_gallery/app_gallery_service_connection.h index 41a04af23..1e1eb7dfc 100644 --- a/services/app_gallery/include/app_gallery_service_connection.h +++ b/services/backup_sa/include/module_app_gallery/app_gallery_service_connection.h @@ -18,6 +18,7 @@ #include #include +#include #include "ability_manager_client.h" #include "ability_connect_callback_stub.h" diff --git a/services/app_gallery/include/i_appgallery_service.h b/services/backup_sa/include/module_app_gallery/i_appgallery_service.h similarity index 100% rename from services/app_gallery/include/i_appgallery_service.h rename to services/backup_sa/include/module_app_gallery/i_appgallery_service.h diff --git a/services/app_gallery/src/app_gallery_dispose_proxy.cpp b/services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp similarity index 97% rename from services/app_gallery/src/app_gallery_dispose_proxy.cpp rename to services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp index 69422cae9..03583076b 100644 --- a/services/app_gallery/src/app_gallery_dispose_proxy.cpp +++ b/services/backup_sa/src/module_app_gallery/app_gallery_dispose_proxy.cpp @@ -16,12 +16,11 @@ #include #include "message_parcel.h" -#include "message_opetion.h" #include "nlohmann/json.hpp" #include "want.h" -#include "app_gallery_dispose_proxy.h" -#include "app_gallery_service_connection.h" +#include "module_app_gallery/app_gallery_dispose_proxy.h" +#include "module_app_gallery/app_gallery_service_connection.h" #include "filemgmt_libhilog.h" namespace OHOS::FileManagement::Backup { diff --git a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp index ed8aa156e..4a1864083 100644 --- a/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp +++ b/services/backup_sa/src/module_ipc/service_reverse_proxy.cpp @@ -15,7 +15,7 @@ #include "module_ipc/service_reverse_proxy.h" -#include "app_gallery_dispose_proxy.h" +#include "module_app_gallery/app_gallery_dispose_proxy.h" #include "b_error/b_error.h" #include "b_error/b_excep_utils.h" #include "filemgmt_libhilog.h" @@ -115,9 +115,9 @@ void ServiceReverseProxy::RestoreOnBundleStarted(int32_t errCode, string bundleN err != ERR_OK) { throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); } - - DisposeErr disposeErr = AppGalleryDisposeProxy::StartRestore(bundleName); - HILOGI("AppGalleryDisposeProxy StartRestore, code=%{public}d, bundleName=%{public}s", disposeOperation, bundleName.c_str()); + AppGalleryDisposeProxy appGalleryDisposeProxy; + DisposeErr disposeErr = appGalleryDisposeProxy.StartRestore(bundleName); + HILOGI("AppGalleryDisposeProxy StartRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); } void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundleName) @@ -138,8 +138,9 @@ void ServiceReverseProxy::RestoreOnBundleFinished(int32_t errCode, string bundle throw BError(BError::Codes::SA_BROKEN_IPC, to_string(err)); } - DisposeErr disposeErr = AppGalleryDisposeProxy::EndRestore(bundleName); - HILOGI("AppGalleryDisposeProxy EndRestore, code=%{public}d, bundleName=%{public}s", disposeOperation, bundleName.c_str()); + AppGalleryDisposeProxy appGalleryDisposeProxy; + DisposeErr disposeErr = appGalleryDisposeProxy.EndRestore(bundleName); + HILOGI("AppGalleryDisposeProxy EndRestore, code=%{public}d, bundleName=%{public}s", disposeErr, bundleName.c_str()); } void ServiceReverseProxy::RestoreOnAllBundlesFinished(int32_t errCode) -- Gitee