解决安全问题单

Signed-off-by: zhangxiaoliang25 <zhangxiaoliang25@huawei.com>
Change-Id: Ia92f4474e9f7a7806ae13b6c77437f84eb0de8a3
Signed-off-by: zhangxiaoliang25 <zhangxiaoliang25@huawei.com>
This commit is contained in:
zhangxiaoliang25 2024-07-23 20:34:10 +08:00
parent 8aed9631aa
commit f6545da659
28 changed files with 631 additions and 66 deletions

View File

@ -66,7 +66,8 @@
"header_files": [
"file_access_ext_ability.h",
"file_access_extension_info.h",
"file_access_ext_stub_impl.h"
"file_access_ext_stub_impl.h",
"file_access_ext_proxy.h"
],
"header_base": "//foundation/filemanagement/user_file_service/interfaces/inner_api/file_access/include"
}

View File

@ -56,8 +56,8 @@ ohos_shared_library("file_access_extension_ability_kit") {
sources = [
"${user_file_service_path}/services/native/file_access_service/src/file_access_service_proxy.cpp",
"src/app_file_access_ext_connection.cpp",
"src/file_access_ext_ability.cpp",
"src/file_access_ext_connection.cpp",
"src/file_access_ext_proxy.cpp",
"src/file_access_ext_stub.cpp",
"src/file_access_ext_stub_impl.cpp",

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef FILE_ACCESS_EXT_CONNECTION_H
#define FILE_ACCESS_EXT_CONNECTION_H
#ifndef APP_FILE_ACCESS_EXT_CONNECTION_H
#define APP_FILE_ACCESS_EXT_CONNECTION_H
#include <atomic>
#include <mutex>
@ -28,15 +28,15 @@
namespace OHOS {
namespace FileAccessFwk {
class FileAccessExtConnection : public AAFwk::AbilityConnectionStub {
class AppFileAccessExtConnection : public AAFwk::AbilityConnectionStub {
public:
FileAccessExtConnection() = default;
virtual ~FileAccessExtConnection();
AppFileAccessExtConnection() = default;
virtual ~AppFileAccessExtConnection();
void OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
void ConnectFileExtAbility(const AAFwk::Want &want, const sptr<IRemoteObject> &token);
void ConnectFileExtAbility(const AAFwk::Want &want);
void DisconnectFileExtAbility();
bool IsExtAbilityConnected();
void OnSchedulerDied(const wptr<IRemoteObject> &remote);
@ -71,4 +71,4 @@ private:
};
} // namespace FileAccessFwk
} // namespace OHOS
#endif // FILE_ACCESS_EXT_CONNECTION_H
#endif // APP_FILE_ACCESS_EXT_CONNECTION_H

View File

@ -25,7 +25,7 @@
#include "bundle_mgr_interface.h"
#include "context.h"
#include "file_access_ext_connection.h"
#include "app_file_access_ext_connection.h"
#include "file_access_extension_info.h"
#include "ifile_access_ext_base.h"
#include "iobserver_callback.h"
@ -50,7 +50,7 @@ namespace {
struct ConnectInfo {
AAFwk::Want want = {};
sptr<FileAccessExtConnection> fileAccessExtConnection = nullptr;
sptr<AppFileAccessExtConnection> fileAccessExtConnection = nullptr;
};
class FileAccessHelper final : public std::enable_shared_from_this<FileAccessHelper> {

View File

@ -21,7 +21,7 @@
*OHOS::FileAccessFwk::FileAccessNotifyManager*;
*OHOS::FileAccessFwk::FileAccessExtStub*;
*OHOS::FileAccessFwk::FileAccessExtStubImpl*;
*OHOS::FileAccessFwk::FileAccessExtConnection*;
*OHOS::FileAccessFwk::FileAccessExtProxy*;
};
local:
*;

View File

@ -13,22 +13,23 @@
* limitations under the License.
*/
#include "file_access_ext_connection.h"
#include "app_file_access_ext_connection.h"
#include <errors.h>
#include <memory>
#include "ability_connect_callback_interface.h"
#include "ability_manager_client.h"
#include "file_access_ext_proxy.h"
#include "file_access_service_proxy.h"
#include "hilog_wrapper.h"
#include "iremote_broker.h"
namespace OHOS {
namespace FileAccessFwk {
std::mutex AppFileAccessExtConnection::mutex_;
std::mutex FileAccessExtConnection::mutex_;
void FileAccessExtConnection::OnAbilityConnectDone(
void AppFileAccessExtConnection::OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
{
std::lock_guard<std::mutex> lock(proxyMutex_);
@ -36,7 +37,7 @@ void FileAccessExtConnection::OnAbilityConnectDone(
HILOG_ERROR("remote is nullptr");
return;
}
fileExtProxy_ = iface_cast<FileAccessExtProxy>(remoteObject);
fileExtProxy_ = iface_cast<IFileAccessExtBase>(remoteObject);
if (fileExtProxy_ == nullptr) {
HILOG_ERROR("fileExtProxy_ is nullptr");
return;
@ -48,7 +49,7 @@ void FileAccessExtConnection::OnAbilityConnectDone(
connectLockInfo_.condition.notify_all();
}
void FileAccessExtConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
void AppFileAccessExtConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
{
std::lock_guard<std::mutex> lock(proxyMutex_);
if (fileExtProxy_) {
@ -58,14 +59,20 @@ void FileAccessExtConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementN
HILOG_INFO("OnAbilityDisconnectDone resultCode=%{public}d", resultCode);
}
void FileAccessExtConnection::ConnectFileExtAbility(const AAFwk::Want &want, const sptr<IRemoteObject> &token)
void AppFileAccessExtConnection::ConnectFileExtAbility(const AAFwk::Want &want)
{
std::unique_lock<std::mutex> lock(proxyMutex_);
if (fileExtProxy_) {
fileExtProxy_ = nullptr;
}
isConnected_.store(false);
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, token);
auto proxy = FileAccessServiceProxy::GetInstance();
if (proxy == nullptr) {
HILOG_ERROR("ConnectFileExtAbility FileAccessServiceProxy GetInstance fail");
return;
}
ErrCode ret = proxy->ConnectFileExtAbility(want, this);
if (ret != ERR_OK) {
HILOG_ERROR("ConnectAbility failed, ret=%{public}d", ret);
return;
@ -79,13 +86,18 @@ void FileAccessExtConnection::ConnectFileExtAbility(const AAFwk::Want &want, con
HILOG_INFO("ConnectFileExtAbility success");
}
void FileAccessExtConnection::DisconnectFileExtAbility()
void AppFileAccessExtConnection::DisconnectFileExtAbility()
{
std::lock_guard<std::mutex> lock(proxyMutex_);
if (fileExtProxy_ != nullptr) {
RemoveFileAccessDeathRecipient(fileExtProxy_->AsObject());
}
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(this);
auto proxy = FileAccessServiceProxy::GetInstance();
if (proxy == nullptr) {
HILOG_ERROR("DisconnectFileExtAbility FileAccessServiceProxy GetInstance fail");
return;
}
ErrCode ret = proxy->DisConnectFileExtAbility(this);
if (ret != ERR_OK) {
HILOG_ERROR("DisconnectAbility failed, ret=%{public}d", ret);
return;
@ -97,17 +109,17 @@ void FileAccessExtConnection::DisconnectFileExtAbility()
HILOG_INFO("DisconnectFileExtAbility done");
}
bool FileAccessExtConnection::IsExtAbilityConnected()
bool AppFileAccessExtConnection::IsExtAbilityConnected()
{
return isConnected_.load();
}
sptr<IFileAccessExtBase> FileAccessExtConnection::GetFileExtProxy()
sptr<IFileAccessExtBase> AppFileAccessExtConnection::GetFileExtProxy()
{
return fileExtProxy_;
}
void FileAccessExtConnection::AddFileAccessDeathRecipient(const sptr<IRemoteObject> &token)
void AppFileAccessExtConnection::AddFileAccessDeathRecipient(const sptr<IRemoteObject> &token)
{
std::lock_guard<std::mutex> lock(deathRecipientMutex_);
if (token != nullptr && callerDeathRecipient_ != nullptr) {
@ -116,14 +128,14 @@ void FileAccessExtConnection::AddFileAccessDeathRecipient(const sptr<IRemoteObje
if (callerDeathRecipient_ == nullptr) {
callerDeathRecipient_ =
new FileAccessDeathRecipient(
std::bind(&FileAccessExtConnection::OnSchedulerDied, this, std::placeholders::_1));
std::bind(&AppFileAccessExtConnection::OnSchedulerDied, this, std::placeholders::_1));
}
if (token != nullptr) {
token->AddDeathRecipient(callerDeathRecipient_);
}
}
void FileAccessExtConnection::RemoveFileAccessDeathRecipient(const sptr<IRemoteObject> &token)
void AppFileAccessExtConnection::RemoveFileAccessDeathRecipient(const sptr<IRemoteObject> &token)
{
std::lock_guard<std::mutex> lock(deathRecipientMutex_);
if (token != nullptr && callerDeathRecipient_ != nullptr) {
@ -131,7 +143,7 @@ void FileAccessExtConnection::RemoveFileAccessDeathRecipient(const sptr<IRemoteO
}
}
void FileAccessExtConnection::OnSchedulerDied(const wptr<IRemoteObject> &remote)
void AppFileAccessExtConnection::OnSchedulerDied(const wptr<IRemoteObject> &remote)
{
std::lock_guard<std::mutex> lock(proxyMutex_);
HILOG_ERROR("OnSchedulerDied");
@ -145,8 +157,9 @@ void FileAccessExtConnection::OnSchedulerDied(const wptr<IRemoteObject> &remote)
}
}
FileAccessExtConnection::~FileAccessExtConnection()
AppFileAccessExtConnection::~AppFileAccessExtConnection()
{
HILOG_INFO("~AppFileAccessExtConnection");
if (isConnected_.load()) {
DisconnectFileExtAbility();
}

View File

@ -198,13 +198,13 @@ std::pair<std::shared_ptr<FileAccessHelper>, int> FileAccessHelper::DoCreatorHel
{
std::unordered_map<std::string, std::shared_ptr<ConnectInfo>> cMap;
for (size_t i = 0; i < wants.size(); i++) {
sptr<FileAccessExtConnection> fileAccessExtConnection(new(std::nothrow) FileAccessExtConnection());
sptr<AppFileAccessExtConnection> fileAccessExtConnection(new(std::nothrow) AppFileAccessExtConnection());
if (fileAccessExtConnection == nullptr) {
HILOG_ERROR("new fileAccessExtConnection fail");
return {nullptr, E_GETRESULT};
}
if (!fileAccessExtConnection->IsExtAbilityConnected()) {
fileAccessExtConnection->ConnectFileExtAbility(wants[i], token);
fileAccessExtConnection->ConnectFileExtAbility(wants[i]);
}
sptr<IFileAccessExtBase> fileExtProxy = fileAccessExtConnection->GetFileExtProxy();
if (fileExtProxy == nullptr) {
@ -346,7 +346,7 @@ sptr<IFileAccessExtBase> FileAccessHelper::GetProxyByBundleName(const std::strin
return nullptr;
}
if (!connectInfo->fileAccessExtConnection->IsExtAbilityConnected()) {
connectInfo->fileAccessExtConnection->ConnectFileExtAbility(connectInfo->want, token_);
connectInfo->fileAccessExtConnection->ConnectFileExtAbility(connectInfo->want);
}
auto fileAccessExtProxy = connectInfo->fileAccessExtConnection->GetFileExtProxy();
if (fileAccessExtProxy == nullptr) {
@ -361,7 +361,7 @@ bool FileAccessHelper::GetProxy()
for (auto iter = cMap_.begin(); iter != cMap_.end(); ++iter) {
auto connectInfo = iter->second;
if (!connectInfo->fileAccessExtConnection->IsExtAbilityConnected()) {
connectInfo->fileAccessExtConnection->ConnectFileExtAbility(connectInfo->want, token_);
connectInfo->fileAccessExtConnection->ConnectFileExtAbility(connectInfo->want);
}
auto fileAccessExtProxy = connectInfo->fileAccessExtConnection->GetFileExtProxy();
if (fileAccessExtProxy == nullptr) {

View File

@ -1929,7 +1929,7 @@ int JsFileAccessExtAbility::MoveFile(const Uri &sourceFile, const Uri &targetPar
napi_create_string_utf8(env, targetParent.ToString().c_str(), targetParent.ToString().length(), &dstUri);
napi_value name = nullptr;
napi_create_string_utf8(env, fileName.c_str(), fileName.length(), &name);
if (srcUri == nullptr || dstUri == nullptr || name ==nullptr) {
if (srcUri == nullptr || dstUri == nullptr || name == nullptr) {
HILOG_ERROR("create sourceFile uri native js value fail.");
return false;
}

View File

@ -98,9 +98,11 @@ ohos_shared_library("file_access_service") {
include_dirs = [
"${user_file_service_path}/services/native/file_access_service/include",
"${user_file_service_path}/interfaces/inner_api/file_access/include",
]
shlib_type = "sa"
sources = [
"native/file_access_service/src/file_access_ext_connection.cpp",
"native/file_access_service/src/file_access_service.cpp",
"native/file_access_service/src/file_access_service_proxy.cpp",
"native/file_access_service/src/file_access_service_stub.cpp",

View File

@ -0,0 +1,77 @@
/*
* Copyright (c) 2022-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* 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 FILE_ACCESS_EXT_CONNECTION_H
#define FILE_ACCESS_EXT_CONNECTION_H
#include <atomic>
#include <mutex>
#include "ability_connect_callback_stub.h"
#include "element_name.h"
#include "ifile_access_ext_base.h"
#include "file_access_ext_proxy.h"
#include "file_access_service.h"
#include "iremote_object.h"
#include "refbase.h"
#include "want.h"
namespace OHOS {
namespace FileAccessFwk {
class FileAccessService;
class FileAccessExtConnection : public AAFwk::AbilityConnectionStub {
public:
FileAccessExtConnection() = default;
virtual ~FileAccessExtConnection() = default;
void OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
void ConnectFileExtAbility(const AAFwk::Want &want, const sptr<IRemoteObject> &token);
void DisconnectFileExtAbility();
bool IsExtAbilityConnected();
sptr<IFileAccessExtBase> GetFileExtProxy();
private:
struct ThreadLockInfo {
std::condition_variable condition;
std::mutex mutex;
bool isReady = false;
};
ThreadLockInfo connectLockInfo_;
static std::mutex mutex_;
std::atomic<bool> isConnected_ = {false};
sptr<IFileAccessExtBase> fileExtProxy_;
};
class AgentFileAccessExtConnection : public AAFwk::AbilityConnectionStub {
public:
AgentFileAccessExtConnection(const sptr<AAFwk::IAbilityConnection>& connection) : connection_(connection){};
virtual ~AgentFileAccessExtConnection();
void OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override;
void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override;
void ConnectFileExtAbility(const AAFwk::Want &want);
void DisconnectFileExtAbility();
private:
const sptr<AAFwk::IAbilityConnection> connection_ = nullptr;
};
} // namespace FileAccessFwk
} // namespace OHOS
#endif // FILE_ACCESS_EXT_CONNECTION_H

View File

@ -25,6 +25,7 @@
#include <vector>
#include "bundle_mgr_interface.h"
#include "file_access_ext_connection.h"
#include "file_access_service_stub.h"
#include "ifile_access_ext_base.h"
#include "holder_manager.h"
@ -36,7 +37,7 @@
namespace OHOS {
namespace FileAccessFwk {
class AgentFileAccessExtConnection;
class ObserverContext {
public:
ObserverContext(sptr<IFileAccessObserver> obs): obs_(obs) {}
@ -226,6 +227,9 @@ public:
virtual void OnStop() override;
int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
void DisconnectAppProxy(const sptr<AAFwk::IAbilityConnection>& connection);
void RemoveAppProxy(const sptr<AAFwk::IAbilityConnection>& connection);
protected:
int32_t RegisterNotify(Uri uri, bool notifyForDescendants, const sptr<IFileAccessObserver> &observer,
const std::shared_ptr<ConnectExtensionInfo> &info) override;
@ -233,8 +237,11 @@ protected:
const std::shared_ptr<ConnectExtensionInfo> &info = nullptr) override;
int32_t CleanAllNotify(Uri uri, const std::shared_ptr<ConnectExtensionInfo> &info) override;
int32_t OnChange(Uri uri, NotifyType notifyType) override;
int32_t GetExensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
int32_t GetExtensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
sptr<IFileAccessExtBase> &extensionProxy) override;
int32_t ConnectFileExtAbility(const AAFwk::Want &want,
const sptr<AAFwk::IAbilityConnection>& connection) override;
int32_t DisConnectFileExtAbility(const sptr<AAFwk::IAbilityConnection>& connection) override;
private:
class ExtensionDeathRecipient : public IRemoteObject::DeathRecipient {
@ -272,6 +279,8 @@ private:
const std::shared_ptr<ConnectExtensionInfo> &info);
sptr<IFileAccessExtBase> FindExtProxyByBundleName(std::string bundleName);
void AddExtProxyInfo(std::string bundleName, sptr<IFileAccessExtBase> extProxy);
// 管理对象 方法
void AddAppProxy(const sptr<AAFwk::IAbilityConnection>& key, sptr<AgentFileAccessExtConnection>& value);
std::shared_ptr<UnloadTimer> unLoadTimer_ = nullptr;
std::shared_ptr<OnDemandTimer> onDemandTimer_ = nullptr;
static sptr<FileAccessService> instance_;
@ -285,6 +294,18 @@ private:
HolderManager<std::shared_ptr<ObserverContext>> obsManager_;
std::mutex mapMutex_;
std::unordered_map<std::string, sptr<IFileAccessExtBase>> cMap_;
class AppDeathRecipient : public IRemoteObject::DeathRecipient {
public:
AppDeathRecipient() {}
virtual void OnRemoteDied(const wptr<IRemoteObject>& remote);
virtual ~AppDeathRecipient() = default;
};
std::mutex appProxyMutex_;
std::unordered_map<size_t, sptr<AgentFileAccessExtConnection>> appProxyMap_;
std::unordered_map<size_t, sptr<AAFwk::IAbilityConnection>> appConnection_;
sptr<IRemoteObject::DeathRecipient> appDeathRecipient_;
};
} // namespace FileAccessFwk
} // namespace OHOS

View File

@ -22,7 +22,9 @@ namespace FileAccessFwk {
CMD_REGISTER_NOTIFY = 0,
CMD_UNREGISTER_NOTIFY,
CMD_ONCHANGE,
CMD_GET_EXTENSION_PROXY
CMD_GET_EXTENSION_PROXY,
CMD_CONNECT_FILE_EXT_ABILITY,
CMD_DISCONNECT_FILE_EXT_ABILITY
};
} // namespace FileAccessFwk
} // namespace OHOS

View File

@ -33,8 +33,11 @@ public:
const std::shared_ptr<ConnectExtensionInfo> &info) override;
int32_t UnregisterNotify(Uri uri, const sptr<IFileAccessObserver> &observer,
const std::shared_ptr<ConnectExtensionInfo> &info) override;
int32_t GetExensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
int32_t GetExtensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
sptr<IFileAccessExtBase> &extensionProxy) override;
int32_t ConnectFileExtAbility(const AAFwk::Want &want,
const sptr<AAFwk::IAbilityConnection>& connection) override;
int32_t DisConnectFileExtAbility(const sptr<AAFwk::IAbilityConnection>& connection) override;
class ServiceProxyLoadCallback : public SystemAbilityLoadCallbackStub {
public:

View File

@ -38,6 +38,8 @@ private:
ErrCode CmdRegisterNotify(MessageParcel &data, MessageParcel &reply);
ErrCode CmdUnregisterNotify(MessageParcel &data, MessageParcel &reply);
ErrCode CmdGetExensionProxy(MessageParcel &data, MessageParcel &reply);
ErrCode CmdConnectFileExtAbility(MessageParcel &data, MessageParcel &reply);
ErrCode CmdDisConnectFileExtAbility(MessageParcel &data, MessageParcel &reply);
bool CheckCallingPermission(const std::string &permission);
using RequestFuncType = int (FileAccessServiceStub::*)(MessageParcel &data, MessageParcel &reply);
std::map<uint32_t, RequestFuncType> stubFuncMap_;

View File

@ -37,6 +37,7 @@ public:
{
std::lock_guard<std::mutex> guard(holderMutex_);
holder_.clear();
HILOG_INFO("~HolderManager holder size: %{public}zu", holder_.size());
}
uint32_t save(Type content)
@ -47,6 +48,7 @@ public:
} while (exist(id));
std::lock_guard<std::mutex> guard(holderMutex_);
holder_.insert(std::pair<uint32_t, Type>(id, content));
HILOG_INFO("save id:%{public}d holder size: %{public}zu", id, holder_.size());
return id;
}
@ -67,8 +69,10 @@ public:
if (iter != holder_.end()) {
auto res = iter->second;
holder_.erase(id);
HILOG_INFO("pop id: %{public}d find holder size: %{public}zu", id, holder_.size());
return res;
}
HILOG_INFO("pop id: %{public}d not find holder size: %{public}zu", id, holder_.size());
return Type();
}
@ -76,7 +80,10 @@ public:
{
std::lock_guard<std::mutex> guard(holderMutex_);
if (holder_.count(id)) {
HILOG_INFO("release id: %{public}d find holder size: %{public}zu", id, holder_.size());
holder_.erase(id);
} else {
HILOG_INFO("release id: %{public}d not find holder size: %{public}zu", id, holder_.size());
}
}

View File

@ -16,6 +16,7 @@
#ifndef I_FILE_ACCESS_SERVICE_BASE_H
#define I_FILE_ACCESS_SERVICE_BASE_H
#include "ability_connect_callback_interface.h"
#include "file_access_helper.h"
#include "iremote_broker.h"
#include "iremote_object.h"
@ -36,8 +37,11 @@ protected:
virtual int32_t UnregisterNotify(Uri uri, const sptr<IFileAccessObserver> &observer,
const std::shared_ptr<ConnectExtensionInfo> &info) = 0;
//Get exension proxy by SA
virtual int32_t GetExensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
virtual int32_t GetExtensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
sptr<IFileAccessExtBase> &extensionProxy) = 0;
virtual int32_t ConnectFileExtAbility(const AAFwk::Want &want,
const sptr<AAFwk::IAbilityConnection>& connection) = 0;
virtual int32_t DisConnectFileExtAbility(const sptr<AAFwk::IAbilityConnection>& connection) = 0;
};
} // namespace FileAccessFwk
} // namespace OHOS

View File

@ -0,0 +1,144 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* 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 "file_access_ext_connection.h"
#include <errors.h>
#include "ability_connect_callback_interface.h"
#include "ability_manager_client.h"
#include "file_access_ext_proxy.h"
#include "hilog_wrapper.h"
#include "iremote_broker.h"
#include "ipc_skeleton.h"
namespace OHOS {
namespace FileAccessFwk {
std::mutex FileAccessExtConnection::mutex_;
const int32_t DEFAULT_USER_ID = -1;
void FileAccessExtConnection::OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
{
HILOG_INFO("OnAbilityConnectDone start");
if (remoteObject == nullptr) {
HILOG_ERROR("remote is nullptr");
return;
}
fileExtProxy_ = iface_cast<FileAccessExtProxy>(remoteObject);
if (fileExtProxy_ == nullptr) {
HILOG_ERROR("FileAccessExtConnection fileExtProxy_ is nullptr");
return;
}
HILOG_INFO("OnAbilityConnectDone set connected info");
isConnected_.store(true);
std::lock_guard<std::mutex> lock(connectLockInfo_.mutex);
connectLockInfo_.isReady = true;
connectLockInfo_.condition.notify_all();
}
void FileAccessExtConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
{
fileExtProxy_ = nullptr;
isConnected_.store(false);
}
void FileAccessExtConnection::ConnectFileExtAbility(const AAFwk::Want &want, const sptr<IRemoteObject> &token)
{
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, DEFAULT_USER_ID);
HILOG_INFO("ConnectFileExtAbility ret: %{public}d ", ret);
if (ret != ERR_OK) {
HILOG_INFO("ConnectAbility ret=%{public}d", ret);
return;
}
std::unique_lock<std::mutex> lock(connectLockInfo_.mutex);
const int WAIT_TIME = 3; // second
if (!connectLockInfo_.condition.wait_for(lock, std::chrono::seconds(WAIT_TIME),
[this] { return fileExtProxy_ != nullptr && connectLockInfo_.isReady; })) {
HILOG_INFO("Wait connect timeout.");
}
}
void FileAccessExtConnection::DisconnectFileExtAbility()
{
fileExtProxy_ = nullptr;
isConnected_.store(false);
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(this);
HILOG_INFO("DisconnectFileExtAbility called end, ret=%{public}d", ret);
}
bool FileAccessExtConnection::IsExtAbilityConnected()
{
return isConnected_.load();
}
sptr<IFileAccessExtBase> FileAccessExtConnection::GetFileExtProxy()
{
return fileExtProxy_;
}
void AgentFileAccessExtConnection::OnAbilityConnectDone(
const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode)
{
HILOG_INFO("start OnAbilityConnectDone");
if (connection_ == nullptr) {
return ;
}
connection_->OnAbilityConnectDone(element, remoteObject, resultCode);
HILOG_INFO("end OnAbilityConnectDone");
}
void AgentFileAccessExtConnection::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode)
{
HILOG_INFO("start OnAbilityDisconnectDone");
if (connection_ == nullptr) {
HILOG_WARN("OnAbilityDisconnectDone connection_ is nullptr");
return;
}
connection_->OnAbilityDisconnectDone(element, resultCode);
FileAccessService::GetInstance()->DisconnectAppProxy(connection_);
FileAccessService::GetInstance()->RemoveAppProxy(connection_);
HILOG_INFO("OnAbilityDisconnectDone resultCode=%{public}d", resultCode);
}
void AgentFileAccessExtConnection::ConnectFileExtAbility(const AAFwk::Want &want)
{
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->ConnectAbility(want, this, DEFAULT_USER_ID);
if (ret != ERR_OK) {
HILOG_ERROR("AgentFileAccessExtConnection ConnectAbility failed, ret=%{public}d", ret);
return;
}
HILOG_INFO("AgentFileAccessExtConnection ConnectFileExtAbility success");
}
void AgentFileAccessExtConnection::DisconnectFileExtAbility()
{
ErrCode ret = AAFwk::AbilityManagerClient::GetInstance()->DisconnectAbility(this);
if (ret != ERR_OK) {
HILOG_ERROR("DisconnectAbility failed, ret=%{public}d", ret);
return;
}
HILOG_INFO("DisconnectFileExtAbility done");
}
AgentFileAccessExtConnection::~AgentFileAccessExtConnection()
{
}
} // namespace FileAccessFwk
} // namespace OHOS

View File

@ -15,13 +15,12 @@
#include "file_access_service.h"
#include <cstddef>
#include <unistd.h>
#include "user_access_tracer.h"
#include "file_access_framework_errno.h"
#include "file_access_ext_connection.h"
#include "file_access_extension_info.h"
#include "file_access_ext_connection.h"
#include "hilog_wrapper.h"
#include "hitrace_meter.h"
#include "ipc_skeleton.h"
@ -141,6 +140,9 @@ void FileAccessService::Init()
if (observerDeathRecipient_ == nullptr) {
observerDeathRecipient_ = sptr(new ObserverDeathRecipient());
}
if (appDeathRecipient_ == nullptr) {
appDeathRecipient_ = sptr(new AppDeathRecipient());
}
}
static bool GetBundleNameFromUri(Uri &uri, string &bundleName)
@ -186,7 +188,7 @@ sptr<IFileAccessExtBase> FileAccessService::ConnectExtension(Uri &uri, const sha
sptr<IFileAccessExtBase> extensionProxy;
{
lock_guard<mutex> lock(mutex_);
int32_t ret = GetExensionProxy(info, extensionProxy);
int32_t ret = GetExtensionProxy(info, extensionProxy);
if (ret != ERR_OK || extensionProxy == nullptr) {
return nullptr;
}
@ -288,6 +290,7 @@ int32_t FileAccessService::OperateObsNode(Uri &uri, bool notifyForDescendants, u
const std::shared_ptr<ConnectExtensionInfo> &info)
{
string uriStr = uri.ToString();
HILOG_INFO("OperateObsNode uriStr: %{public}s", uriStr.c_str());
lock_guard<mutex> lock(nodeMutex_);
auto iter = relationshipMap_.find(uriStr);
shared_ptr<ObserverNode> obsNode;
@ -340,7 +343,7 @@ int32_t FileAccessService::RegisterNotifyImpl(Uri uri, bool notifyForDescendants
{
UserAccessTracer trace;
trace.Start("RegisterNotifyImpl");
std::string token = IPCSkeleton::ResetCallingIdentity();
// std::string token = IPCSkeleton::ResetCallingIdentity();
shared_ptr<ObserverContext> obsContext = make_shared<ObserverContext>(observer);
// find if obsManager_ has this callback.
uint32_t code = obsManager_.getId([obsContext](const shared_ptr<ObserverContext> &afterContext) {
@ -384,6 +387,7 @@ void FileAccessService::RemoveRelations(string &uriStr, shared_ptr<ObserverNode>
int FileAccessService::FindUri(const string &uriStr, shared_ptr<ObserverNode> &outObsNode)
{
HILOG_INFO("uriStr: %{public}s", uriStr.c_str());
lock_guard<mutex> lock(nodeMutex_);
auto iter = relationshipMap_.find(uriStr);
if (iter == relationshipMap_.end()) {
@ -600,7 +604,9 @@ int32_t FileAccessService::OnChange(Uri uri, NotifyType notifyType)
bool FileAccessService::IsUnused()
{
return obsManager_.isEmpty();
HILOG_INFO("IsUnused: obsManager_: %{public}d, appProxyMap_: %{public}d",
obsManager_.isEmpty(), appProxyMap_.empty());
return obsManager_.isEmpty() && appProxyMap_.empty();
}
void FileAccessService::InitTimer()
@ -648,7 +654,41 @@ void FileAccessService::InitTimer()
unLoadTimer_->start();
}
int32_t FileAccessService::GetExensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
int32_t FileAccessService::ConnectFileExtAbility(const AAFwk::Want &want,
const sptr<AAFwk::IAbilityConnection>& connection)
{
HILOG_INFO("ConnectFileExtAbility start");
if (connection == nullptr) {
HILOG_ERROR("connection is nullptr");
return E_CONNECT;
}
sptr<AgentFileAccessExtConnection> fileAccessExtConnection(
new(std::nothrow) AgentFileAccessExtConnection(connection));
if (fileAccessExtConnection == nullptr) {
HILOG_ERROR("new fileAccessExtConnection fail");
return E_CONNECT;
}
fileAccessExtConnection->ConnectFileExtAbility(want);
AddAppProxy(connection, fileAccessExtConnection);
return ERR_OK;
}
int32_t FileAccessService::DisConnectFileExtAbility(const sptr<AAFwk::IAbilityConnection>& connection)
{
HILOG_INFO("ConnectFileExtAbility start");
if (connection == nullptr) {
HILOG_ERROR("connection is nullptr");
return E_CONNECT;
}
DisconnectAppProxy(connection);
RemoveAppProxy(connection);
return ERR_OK;
}
int32_t FileAccessService::GetExtensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
sptr<IFileAccessExtBase> &extensionProxy)
{
sptr<FileAccessExtConnection> fileAccessExtConnection(new(std::nothrow) FileAccessExtConnection());
@ -703,5 +743,75 @@ void FileAccessService::AddExtProxyInfo(std::string bundleName, sptr<IFileAccess
lock_guard<mutex> lock(mapMutex_);
cMap_.emplace(bundleName, extProxy);
}
void FileAccessService::AddAppProxy(const sptr<AAFwk::IAbilityConnection>& connection,
sptr<AgentFileAccessExtConnection>& value)
{
if (connection == nullptr || value == nullptr) {
HILOG_ERROR("key is null or value is null");
return;
}
size_t key = reinterpret_cast<size_t>(connection->AsObject().GetRefPtr());
HILOG_INFO("sa add key, %{public}zu", key);
lock_guard<mutex> lock(appProxyMutex_);
if (appProxyMap_.count(key)) {
HILOG_INFO("sa had proxy,needn't create connection");
return;
}
connection->AsObject()->AddDeathRecipient(appDeathRecipient_);
appProxyMap_[key] = value;
appConnection_[key] = connection;
HILOG_INFO("appProxyMap_ size: %{public}zu", appProxyMap_.size());
}
void FileAccessService::RemoveAppProxy(const sptr<AAFwk::IAbilityConnection>& connection)
{
if (connection == nullptr) {
HILOG_WARN("key is null");
return;
}
size_t key = reinterpret_cast<size_t>(connection->AsObject().GetRefPtr());
if (appProxyMap_.find(key) == appProxyMap_.end()) {
HILOG_WARN("appProxyMap_ not key: %{public}zu", key);
return;
}
lock_guard<mutex> lock(appProxyMutex_);
if (appProxyMap_.find(key) == appProxyMap_.end()) {
HILOG_INFO("appProxyMap_ not key");
return;
}
appProxyMap_.erase(key);
appConnection_.erase(key);
HILOG_INFO("appProxyMap_ size: %{public}zu", appProxyMap_.size());
}
void FileAccessService::DisconnectAppProxy(const sptr<AAFwk::IAbilityConnection>& connection)
{
size_t key = reinterpret_cast<size_t>(connection->AsObject().GetRefPtr());
lock_guard<mutex> lock(appProxyMutex_);
if (appProxyMap_.find(key) == appProxyMap_.end()) {
HILOG_WARN("appProxyMap_ not key: %{public}zu", key);
return;
}
HILOG_INFO("DisconnectAppProxy DisconnectFileExtAbility key: %{public}zu", key);
if (appProxyMap_[key] != nullptr) {
appProxyMap_[key]->DisconnectFileExtAbility();
}
}
void FileAccessService::AppDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
HILOG_INFO("FileAccessService::AppDeathRecipient::OnRemoteDied, remote obj died.");
if (remote == nullptr) {
HILOG_ERROR("remote is nullptr");
return;
}
auto remoteBroker = iface_cast<AAFwk::IAbilityConnection>(remote.promote());
size_t key = reinterpret_cast<size_t>(remoteBroker->AsObject().GetRefPtr());
HILOG_INFO("remote: %{public}zu", key);
FileAccessService::GetInstance()->RemoveAppProxy(remoteBroker);
}
} // namespace FileAccessFwk
} // namespace OHOS

View File

@ -295,12 +295,103 @@ int32_t FileAccessServiceProxy::UnregisterNotify(Uri uri, const sptr<IFileAccess
return result;
}
int32_t FileAccessServiceProxy::ConnectFileExtAbility(const AAFwk::Want &want,
const sptr<AAFwk::IAbilityConnection>& connection)
{
UserAccessTracer trace;
trace.Start("ConnectFileExtAbility");
MessageParcel data;
if (!data.WriteInterfaceToken(FileAccessServiceProxy::GetDescriptor())) {
HILOG_ERROR("WriteInterfaceToken failed");
return E_IPCS;
}
int32_t FileAccessServiceProxy::GetExensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
if (!data.WriteParcelable(&want)) {
HILOG_ERROR("fail to WriteParcelable want");
return E_IPCS;
}
if (connection == nullptr || connection->AsObject() == nullptr) {
HILOG_ERROR("connection is nullptr");
return E_GETINFO;
}
if (!data.WriteRemoteObject(connection->AsObject())) {
HILOG_ERROR("fail to WriteParcelable connection");
return E_IPCS;
}
MessageParcel reply;
MessageOption option;
auto remote = Remote();
if (!remote) {
HILOG_ERROR("failed to get remote");
return E_IPCS;
}
int err = remote->SendRequest(static_cast<uint32_t>(
FileAccessServiceInterfaceCode::CMD_CONNECT_FILE_EXT_ABILITY), data, reply, option);
if (err != ERR_OK) {
HILOG_ERROR("fail to SendRequest. err: %{public}d", err);
return err;
}
int ret = E_IPCS;
if (!reply.ReadInt32(ret) || ret != ERR_OK) {
HILOG_ERROR("ConnectFileExtAbility operation failed ret : %{public}d", ret);
return ret;
}
return ERR_OK;
}
int32_t FileAccessServiceProxy::DisConnectFileExtAbility(const sptr<AAFwk::IAbilityConnection>& connection)
{
UserAccessTracer trace;
trace.Start("DisConnectFileExtAbility");
MessageParcel data;
if (!data.WriteInterfaceToken(FileAccessServiceProxy::GetDescriptor())) {
HILOG_ERROR("WriteInterfaceToken failed");
return E_IPCS;
}
if (connection == nullptr || connection->AsObject() == nullptr) {
HILOG_ERROR("connection is nullptr");
return E_GETINFO;
}
if (!data.WriteRemoteObject(connection->AsObject())) {
HILOG_ERROR("fail to WriteParcelable connection");
return E_IPCS;
}
MessageParcel reply;
MessageOption option;
auto remote = Remote();
if (!remote) {
HILOG_ERROR("failed to get remote");
return E_IPCS;
}
int err = remote->SendRequest(static_cast<uint32_t>(
FileAccessServiceInterfaceCode::CMD_DISCONNECT_FILE_EXT_ABILITY), data, reply, option);
if (err != ERR_OK) {
HILOG_ERROR("fail to SendRequest. err: %{public}d", err);
return err;
}
int ret = E_IPCS;
if (!reply.ReadInt32(ret) || ret != ERR_OK) {
HILOG_ERROR("DisConnectFileExtAbility operation failed ret : %{public}d", ret);
return ret;
}
return ERR_OK;
}
int32_t FileAccessServiceProxy::GetExtensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
sptr<IFileAccessExtBase> &extensionProxy)
{
UserAccessTracer trace;
trace.Start("GetExensionProxy");
trace.Start("GetExtensionProxy");
MessageParcel data;
if (!data.WriteInterfaceToken(FileAccessServiceProxy::GetDescriptor())) {
HILOG_ERROR("WriteInterfaceToken failed");
@ -333,7 +424,7 @@ int32_t FileAccessServiceProxy::GetExensionProxy(const std::shared_ptr<ConnectEx
int ret = E_IPCS;
if (!reply.ReadInt32(ret) || ret != ERR_OK) {
HILOG_ERROR("GetExensionProxy operation failed ret : %{public}d", ret);
HILOG_ERROR("GetExtensionProxy operation failed ret : %{public}d", ret);
return ret;
}

View File

@ -43,6 +43,10 @@ FileAccessServiceStub::FileAccessServiceStub()
&FileAccessServiceStub::CmdUnregisterNotify;
stubFuncMap_[static_cast<uint32_t>(FileAccessServiceInterfaceCode::CMD_ONCHANGE)] =
&FileAccessServiceStub::CmdOnChange;
stubFuncMap_[static_cast<uint32_t>(FileAccessServiceInterfaceCode::CMD_CONNECT_FILE_EXT_ABILITY)] =
&FileAccessServiceStub::CmdConnectFileExtAbility;
stubFuncMap_[static_cast<uint32_t>(FileAccessServiceInterfaceCode::CMD_DISCONNECT_FILE_EXT_ABILITY)] =
&FileAccessServiceStub::CmdDisConnectFileExtAbility;
}
FileAccessServiceStub::~FileAccessServiceStub()
@ -190,6 +194,51 @@ bool FileAccessServiceStub::CheckCallingPermission(const std::string &permission
return true;
}
ErrCode FileAccessServiceStub::CmdConnectFileExtAbility(MessageParcel &data, MessageParcel &reply)
{
UserAccessTracer trace;
trace.Start("CmdConnectFileExtAbility");
std::shared_ptr<AAFwk::Want> wantPtr(data.ReadParcelable<AAFwk::Want>());
if (wantPtr == nullptr) {
return E_IPCS;
}
AAFwk::Want want = AAFwk::Want(*wantPtr);
sptr<AAFwk::IAbilityConnection> connection = iface_cast<AAFwk::IAbilityConnection>(data.ReadRemoteObject());
if (!connection) {
HILOG_ERROR("fail to read connection");
return E_IPCS;
}
int ret = ConnectFileExtAbility(want, connection);
if (!reply.WriteInt32(ret)) {
HILOG_ERROR("fail to CmdConnectFileExtAbility");
return E_IPCS;
}
return ERR_OK;
}
ErrCode FileAccessServiceStub::CmdDisConnectFileExtAbility(MessageParcel &data, MessageParcel &reply)
{
UserAccessTracer trace;
trace.Start("CmdDisConnectFileExtAbility");
sptr<AAFwk::IAbilityConnection> connection = iface_cast<AAFwk::IAbilityConnection>(data.ReadRemoteObject());
if (!connection) {
HILOG_ERROR("fail to read connection");
return E_IPCS;
}
int ret = DisConnectFileExtAbility(connection);
if (!reply.WriteInt32(ret)) {
HILOG_ERROR("fail to CmdDisConnectFileExtAbility");
return E_IPCS;
}
return ERR_OK;
}
ErrCode FileAccessServiceStub::CmdGetExensionProxy(MessageParcel &data, MessageParcel &reply)
{
UserAccessTracer trace;
@ -201,9 +250,9 @@ ErrCode FileAccessServiceStub::CmdGetExensionProxy(MessageParcel &data, MessageP
}
sptr<IFileAccessExtBase> extensionProxy;
int ret = GetExensionProxy(connectExtensionInfo, extensionProxy);
int ret = GetExtensionProxy(connectExtensionInfo, extensionProxy);
if (!reply.WriteInt32(ret) || extensionProxy == nullptr) {
HILOG_ERROR("fail to GetExensionProxy");
HILOG_ERROR("fail to GetExtensionProxy");
return E_IPCS;
}
if (!reply.WriteRemoteObject(extensionProxy->AsObject())) {

View File

@ -21,7 +21,9 @@ ohos_fuzztest("FileAccessExtConnectionFuzzTest") {
"${user_file_service_path}/test/fuzztest/fileaccessextconnection_fuzzer"
include_dirs = [
"${ability_runtime_path}/interfaces/inner_api/ability_manager/include",
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
"${user_file_service_path}/interfaces/inner_api/file_access/include",
"${user_file_service_path}/services/native/file_access_service/include",
"${user_file_service_path}/interfaces/kits/js/src/common",
"${user_file_service_path}/utils",
]
@ -32,8 +34,8 @@ ohos_fuzztest("FileAccessExtConnectionFuzzTest") {
"-fno-omit-frame-pointer",
]
sources = [
"${user_file_service_path}/interfaces/inner_api/file_access/src/file_access_ext_connection.cpp",
"${user_file_service_path}/interfaces/inner_api/file_access/src/file_access_ext_proxy.cpp",
"${user_file_service_path}/services/native/file_access_service/src/file_access_ext_connection.cpp",
"${user_file_service_path}/test/fuzztest/fileaccessextconnection_fuzzer/fileaccessextconnection_fuzzer.cpp",
]

View File

@ -51,6 +51,21 @@ bool GetFileExtProxyFuzzTest(shared_ptr<FileAccessExtConnection> conn)
return true;
}
bool ConnectFileExtAbility(shared_ptr<FileAccessExtConnection> conn)
{
AAFwk::Want want;
sptr<IRemoteObject> remoteObject = nullptr;
conn->ConnectFileExtAbility(want, remoteObject);
return true;
}
bool DisconnectFileExtAbility(shared_ptr<FileAccessExtConnection> conn)
{
conn->DisconnectFileExtAbility();
return true;
}
} // namespace OHOS
/* Fuzzer entry point */
@ -65,6 +80,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
OHOS::OnAbilityDisconnectDoneFuzzTest(conn);
OHOS::IsExtAbilityConnectedFuzzTest(conn);
OHOS::GetFileExtProxyFuzzTest(conn);
OHOS::ConnectFileExtAbility(conn);
OHOS::DisconnectFileExtAbility(conn);
return 0;
}

View File

@ -29,9 +29,12 @@ public:
const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
int32_t UnregisterNotify(Uri uri, const sptr<IFileAccessObserver> &observer,
const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
int32_t GetExensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
int32_t GetExtensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
sptr<IFileAccessExtBase> &extensionProxy) override { return 0; }
int32_t CleanAllNotify(Uri uri, const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
int32_t ConnectFileExtAbility(const AAFwk::Want &want,
const sptr<AAFwk::IAbilityConnection>& connection) override { return 0; };
int32_t DisConnectFileExtAbility(const sptr<AAFwk::IAbilityConnection>& connection) override { return 0; };
};
} // namespace FileAccessFwk
} // namespace OHOS

View File

@ -92,7 +92,7 @@ bool GetExensionProxyFuzzTest(shared_ptr<FileAccessServiceProxy> proxy, const ui
auto info = make_shared<ConnectExtensionInfo>();
sptr<IFileAccessExtBase> extensionProxy = nullptr;
proxy->GetExensionProxy(info, extensionProxy);
proxy->GetExtensionProxy(info, extensionProxy);
return true;
}
} // namespace OHOS

View File

@ -29,9 +29,12 @@ public:
const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
int32_t UnregisterNotify(Uri uri, const sptr<IFileAccessObserver> &observer,
const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
int32_t GetExensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
int32_t GetExtensionProxy(const std::shared_ptr<ConnectExtensionInfo> &info,
sptr<IFileAccessExtBase> &extensionProxy) override { return 0; }
int32_t CleanAllNotify(Uri uri, const std::shared_ptr<ConnectExtensionInfo> &info) override { return 0; }
int32_t ConnectFileExtAbility(const AAFwk::Want &want,
const sptr<AAFwk::IAbilityConnection>& connection) override { return 0; }
int32_t DisConnectFileExtAbility(const sptr<AAFwk::IAbilityConnection>& connection) override { return 0; }
};
} // namespace FileAccessFwk
} // namespace OHOS

View File

@ -350,7 +350,7 @@ HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_UnregisterNotify_
/**
* @tc.number: user_file_service_file_access_service_proxy_GetExensionProxy_0000
* @tc.name: file_access_service_proxy_GetExensionProxy_0000
* @tc.desc: Test function of GetExensionProxy interface for ERROR.
* @tc.desc: Test function of GetExtensionProxy interface for ERROR.
* @tc.size: MEDIUM
* @tc.type: FUNC
* @tc.level Level 3
@ -365,36 +365,36 @@ HWTEST_F(FileAccessServiceProxyTest, file_access_service_proxy_GetExensionProxy_
shared_ptr<ConnectExtensionInfo> info = nullptr;
sptr<IFileAccessExtBase> extensionProxy = nullptr;
EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(false));
auto result = proxy->GetExensionProxy(info, extensionProxy);
auto result = proxy->GetExtensionProxy(info, extensionProxy);
EXPECT_EQ(result, E_IPCS);
EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true));
result = proxy->GetExensionProxy(info, extensionProxy);
result = proxy->GetExtensionProxy(info, extensionProxy);
EXPECT_EQ(result, E_GETINFO);
info = make_shared<ConnectExtensionInfo>();
EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(false));
result = proxy->GetExensionProxy(info, extensionProxy);
result = proxy->GetExtensionProxy(info, extensionProxy);
EXPECT_EQ(result, E_IPCS);
EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true));
EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(E_URIS));
result = proxy->GetExensionProxy(info, extensionProxy);
result = proxy->GetExtensionProxy(info, extensionProxy);
EXPECT_EQ(result, E_URIS);
EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true))
.WillOnce(Return(false));
EXPECT_CALL(*insMoc, Int()).WillOnce(Return(ERR_OK));
EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK));
result = proxy->GetExensionProxy(info, extensionProxy);
result = proxy->GetExtensionProxy(info, extensionProxy);
EXPECT_EQ(result, ERR_OK);
EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true))
.WillOnce(Return(true));
EXPECT_CALL(*insMoc, Int()).WillOnce(Return(E_IPCS));
EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK));
result = proxy->GetExensionProxy(info, extensionProxy);
result = proxy->GetExtensionProxy(info, extensionProxy);
EXPECT_EQ(result, E_IPCS);
EXPECT_CALL(*insMoc, Bool()).WillOnce(Return(true)).WillOnce(Return(true)).WillOnce(Return(true))
.WillOnce(Return(true));
EXPECT_CALL(*insMoc, Int()).WillOnce(Return(ERR_OK));
EXPECT_CALL(*impl, SendRequest(_, _, _, _)).WillOnce(Return(ERR_OK));
result = proxy->GetExensionProxy(info, extensionProxy);
result = proxy->GetExtensionProxy(info, extensionProxy);
EXPECT_EQ(result, E_IPCS);
} catch (...) {
GTEST_LOG_(ERROR) << "FileAccessServiceProxyTest occurs an exception.";

View File

@ -58,7 +58,7 @@ int32_t FileAccessServiceProxy::OnChange(Uri uri, NotifyType notifyType)
return ERR_OK;
}
int32_t FileAccessServiceProxy::GetExensionProxy(const std::shared_ptr<ConnectExtensionInfo> &,
int32_t FileAccessServiceProxy::GetExtensionProxy(const std::shared_ptr<ConnectExtensionInfo> &,
sptr<IFileAccessExtBase> &)
{
return 0;
@ -70,6 +70,17 @@ int32_t FileAccessServiceProxy::UnregisterNotify(Uri, const sptr<IFileAccessObse
return 0;
}
int32_t FileAccessServiceProxy::ConnectFileExtAbility(const AAFwk::Want &,
const sptr<AAFwk::IAbilityConnection>&)
{
return 0;
}
int32_t FileAccessServiceProxy::DisConnectFileExtAbility(const sptr<AAFwk::IAbilityConnection>&)
{
return 0;
}
void FileAccessExtAbility::Init(const std::shared_ptr<AbilityLocalRecord> &record,
const std::shared_ptr<OHOSApplication> &application,
std::shared_ptr<AbilityHandler> &handler,

View File

@ -28,13 +28,16 @@ public:
const sptr<IFileAccessObserver> &observer, const std::shared_ptr<ConnectExtensionInfo> &info));
MOCK_METHOD3(UnregisterNotify, int32_t(Uri uri, const sptr<IFileAccessObserver> &observer,
const std::shared_ptr<ConnectExtensionInfo> &info));
MOCK_METHOD2(GetExensionProxy, int32_t(const std::shared_ptr<ConnectExtensionInfo> &info,
MOCK_METHOD2(GetExtensionProxy, int32_t(const std::shared_ptr<ConnectExtensionInfo> &info,
sptr<IFileAccessExtBase> &extensionProxy));
MOCK_METHOD0(AsObject, sptr<IRemoteObject>());
MOCK_METHOD2(CleanAllNotify, int32_t(Uri uri, const std::shared_ptr<ConnectExtensionInfo> &info));
MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply,
MessageOption &option));
MOCK_METHOD4(SendRequest, int(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option));
MOCK_METHOD2(ConnectFileExtAbility, int32_t(const AAFwk::Want &want,
const sptr<AAFwk::IAbilityConnection>& connection));
MOCK_METHOD1(DisConnectFileExtAbility, int32_t(const sptr<AAFwk::IAbilityConnection>& connection));
};
} // namespace FileAccessFwk
} // namespace OHOS