mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 14:30:21 +00:00
hidumper 导出信息内容整改
Signed-off-by: wangyang2022 <wangyang412@huawei.com> Change-Id: I94da5d44a97439edb6643fd1c58e5957df7000e8
This commit is contained in:
parent
992cab394a
commit
987fbba21b
33
services/base/include/dms_dumper.h
Normal file
33
services/base/include/dms_dumper.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DMS_DUMPER_H
|
||||
#define OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DMS_DUMPER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "refbase.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DmsDumper : public virtual RefBase {
|
||||
public:
|
||||
DmsDumper() = default;
|
||||
virtual ~DmsDumper() = default;
|
||||
virtual bool ProcessDistributedSchedDump(const std::vector<std::string>& args, std::string& result) = 0;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_SCHED_INTERFACES_INNERKITS_DMS_DUMPER_H
|
@ -39,6 +39,7 @@ ohos_shared_library("distributed_ability_manager_svr") {
|
||||
"src/continuation_manager/device_selection_notifier_stub.cpp",
|
||||
"src/continuation_manager/notifier_death_recipient.cpp",
|
||||
"src/continuation_manager/notifier_info.cpp",
|
||||
"src/distributed_ability_manager_dumper.cpp",
|
||||
"src/distributed_ability_manager_service.cpp",
|
||||
"src/distributed_ability_manager_stub.cpp",
|
||||
]
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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_DISTRIBUTED_ABILITY_MANAGER_DUMPER_H
|
||||
#define OHOS_DISTRIBUTED_ABILITY_MANAGER_DUMPER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "dms_dumper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DistributedAbilityManagerDumper {
|
||||
public:
|
||||
static bool Dump(const sptr<DmsDumper>& dmsDumper, const std::vector<std::string>& args, std::string& result);
|
||||
private:
|
||||
DistributedAbilityManagerDumper() = default;
|
||||
~DistributedAbilityManagerDumper() = default;
|
||||
|
||||
static void ShowHelp(std::string& result);
|
||||
static void IllegalInput(std::string& result);
|
||||
static bool CanDump();
|
||||
static bool ProcessDistributedSchedDump(const sptr<DmsDumper>& dmsDumper,
|
||||
const std::vector<std::string>& args, std::string& result);
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // OHOS_DISTRIBUTED_ABILITY_MANAGER_DUMPER_H
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "continuation_manager/notifier_info.h"
|
||||
#include "distributed_ability_manager_stub.h"
|
||||
#include "dms_dumper.h"
|
||||
#include "dms_notifier.h"
|
||||
#include "event_handler.h"
|
||||
#include "single_instance.h"
|
||||
@ -26,7 +27,7 @@
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DistributedAbilityManagerService : public SystemAbility, public DistributedAbilityManagerStub,
|
||||
public DmsNotifier {
|
||||
public DmsNotifier, public DmsDumper {
|
||||
DECLARE_SYSTEM_ABILITY(DistributedAbilityManagerService);
|
||||
|
||||
public:
|
||||
@ -56,7 +57,8 @@ public:
|
||||
const DeviceConnectStatus& deviceConnectStatus) override;
|
||||
int32_t StartDeviceManager(
|
||||
int32_t token, const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams = nullptr) override;
|
||||
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
bool ProcessDistributedSchedDump(const std::vector<std::string>& args, std::string& result) override;
|
||||
private:
|
||||
bool IsExceededRegisterMaxNum(uint32_t accessToken);
|
||||
bool IsContinuationModeValid(ContinuationMode continuationMode);
|
||||
@ -91,11 +93,13 @@ private:
|
||||
using ConnectAbilityFunc = int32_t(*)(const sptr<DmsNotifier>& dmsNotifier, int32_t token,
|
||||
const std::shared_ptr<ContinuationExtraParams>& continuationExtraParams);
|
||||
using DisconnectAbilityFunc = int32_t(*)();
|
||||
using DistributedSchedDumpFunc = bool(*)(const std::vector<std::string>& args, std::string& result);
|
||||
OnRemoteRequestFunc onRemoteRequestFunc_ = nullptr;
|
||||
DeviceOnlineNotifyFunc deviceOnlineNotifyFunc_ = nullptr;
|
||||
DeviceOfflineNotifyFunc deviceOfflineNotifyFunc_ = nullptr;
|
||||
ConnectAbilityFunc connectAbilityFunc_ = nullptr;
|
||||
DisconnectAbilityFunc disconnectAbilityFunc_ = nullptr;
|
||||
DistributedSchedDumpFunc distributedSchedDumpFunc_ = nullptr;
|
||||
|
||||
std::atomic_bool isLoaded_ = false;
|
||||
std::mutex libLoadLock_;
|
||||
|
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "distributed_ability_manager_dumper.h"
|
||||
|
||||
#include "distributed_ability_manager_service.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "ipc_skeleton.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "DistributedAbilityManagerDumper";
|
||||
constexpr int32_t UID_HIDUMPER = 1212;
|
||||
constexpr size_t MIN_ARGS_SIZE = 1;
|
||||
const std::string ARGS_HELP = "-h";
|
||||
const std::string ARGS_CONNECT_REMOTE_ABILITY = "-connect";
|
||||
}
|
||||
|
||||
bool DistributedAbilityManagerDumper::Dump(const sptr<DmsDumper>& dmsDumper, const std::vector<std::string>& args,
|
||||
std::string& result)
|
||||
{
|
||||
result.clear();
|
||||
if (!CanDump()) {
|
||||
result.append("Dump failed, not allowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.size() < MIN_ARGS_SIZE) {
|
||||
return ProcessDistributedSchedDump(dmsDumper, args, result);
|
||||
}
|
||||
|
||||
if (args.size() == MIN_ARGS_SIZE) {
|
||||
// -h
|
||||
if (args[0] == ARGS_HELP) {
|
||||
ShowHelp(result);
|
||||
return true;
|
||||
}
|
||||
// -connect
|
||||
if (args[0] == ARGS_CONNECT_REMOTE_ABILITY) {
|
||||
return ProcessDistributedSchedDump(dmsDumper, args, result);
|
||||
}
|
||||
}
|
||||
IllegalInput(result);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DistributedAbilityManagerDumper::ProcessDistributedSchedDump(const sptr<DmsDumper>& dmsDumper,
|
||||
const std::vector<std::string>& args, std::string& result)
|
||||
{
|
||||
if (dmsDumper == nullptr) {
|
||||
HILOGE("dumper is nullptr");
|
||||
return false;
|
||||
}
|
||||
return dmsDumper->ProcessDistributedSchedDump(args, result);
|
||||
}
|
||||
|
||||
void DistributedAbilityManagerDumper::ShowHelp(std::string& result)
|
||||
{
|
||||
result.append("DistributedSched Dump options:\n")
|
||||
.append(" [-h] [cmd]...\n")
|
||||
.append("cmd maybe one of:\n")
|
||||
.append(" -connect: show all connected remote abilities.\n");
|
||||
}
|
||||
|
||||
void DistributedAbilityManagerDumper::IllegalInput(std::string& result)
|
||||
{
|
||||
result.append("The arguments are illegal and you can enter '-h' for help.\n");
|
||||
}
|
||||
|
||||
bool DistributedAbilityManagerDumper::CanDump()
|
||||
{
|
||||
auto callingUid = IPCSkeleton::GetCallingUid();
|
||||
HILOGI("calling uid = %{public}u", callingUid);
|
||||
if (callingUid != UID_HIDUMPER) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -23,8 +23,10 @@
|
||||
#include "continuation_manager/device_selection_notifier_proxy.h"
|
||||
#include "continuation_manager/notifier_death_recipient.h"
|
||||
#include "dlfcn.h"
|
||||
#include "distributed_ability_manager_dumper.h"
|
||||
#include "dtbschedmgr_device_info_storage.h"
|
||||
#include "dtbschedmgr_log.h"
|
||||
#include "file_ex.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "parameters.h"
|
||||
@ -133,6 +135,11 @@ bool DistributedAbilityManagerService::InitFunc()
|
||||
HILOGE("get DisconnectAbility function error");
|
||||
return false;
|
||||
}
|
||||
distributedSchedDumpFunc_ = reinterpret_cast<DistributedSchedDumpFunc>(dlsym(dmsImplHandle_, "DistributedSchedDump"));
|
||||
if (distributedSchedDumpFunc_ == nullptr) {
|
||||
HILOGE("get Dump function error");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -724,5 +731,36 @@ bool DistributedAbilityManagerService::IsDistributedSchedLoaded()
|
||||
{
|
||||
return isLoaded_;
|
||||
}
|
||||
|
||||
int32_t DistributedAbilityManagerService::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
std::vector<std::string> argsInStr8;
|
||||
for (const auto& arg : args) {
|
||||
argsInStr8.emplace_back(Str16ToStr8(arg));
|
||||
}
|
||||
std::string result;
|
||||
DistributedAbilityManagerDumper::Dump(this, argsInStr8, result);
|
||||
|
||||
if (!SaveStringToFd(fd, result)) {
|
||||
HILOGE("save to fd failed");
|
||||
return DMS_WRITE_FILE_FAILED_ERR;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
bool DistributedAbilityManagerService::ProcessDistributedSchedDump(const std::vector<std::string>& args, std::string& result)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(libLoadLock_);
|
||||
if (!IsDistributedSchedLoaded() || distributedSchedDumpFunc_ == nullptr) {
|
||||
result.append("<none info>\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!distributedSchedDumpFunc_(args, result)) {
|
||||
HILOGE("distributedSched dump failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -101,7 +101,6 @@ public:
|
||||
#endif
|
||||
void ProcessConnectDied(const sptr<IRemoteObject>& connect);
|
||||
void ProcessDeviceOffline(const std::string& deviceId);
|
||||
int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
|
||||
void DumpConnectInfo(std::string& info);
|
||||
void DumpSessionsLocked(const std::list<ConnectAbilitySession>& sessionsList, std::string& info);
|
||||
void DumpElementLocked(const std::list<AppExecFwk::ElementName>& elementsList, std::string& info);
|
||||
|
@ -23,10 +23,8 @@ namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
constexpr size_t MIN_ARGS_SIZE = 1;
|
||||
const std::string ARGS_HELP = "-h";
|
||||
const std::string ARGS_CONNECT_REMOTE_ABILITY = "-connect";
|
||||
const std::string TAG = "DistributedSchedDumper";
|
||||
constexpr int32_t UID_ROOT = 0;
|
||||
}
|
||||
|
||||
bool DistributedSchedDumper::DumpDefault(std::string& result)
|
||||
@ -40,57 +38,24 @@ bool DistributedSchedDumper::DumpDefault(std::string& result)
|
||||
bool DistributedSchedDumper::Dump(const std::vector<std::string>& args, std::string& result)
|
||||
{
|
||||
result.clear();
|
||||
if (!CanDump()) {
|
||||
result.append("Dump failed, not allowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (args.size() < MIN_ARGS_SIZE) {
|
||||
return DumpDefault(result);
|
||||
}
|
||||
|
||||
if (args.size() == MIN_ARGS_SIZE) {
|
||||
// -h
|
||||
if (args[0] == ARGS_HELP) {
|
||||
ShowHelp(result);
|
||||
return true;
|
||||
}
|
||||
// -connect
|
||||
if (args[0] == ARGS_CONNECT_REMOTE_ABILITY) {
|
||||
ShowConnectRemoteAbility(result);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
IllegalInput(result);
|
||||
return false;
|
||||
}
|
||||
|
||||
void DistributedSchedDumper::ShowHelp(std::string& result)
|
||||
{
|
||||
result.append("DistributedSched Dump options:\n")
|
||||
.append(" [-h] [cmd]...\n")
|
||||
.append("cmd maybe one of:\n")
|
||||
.append(" -connect: show all connected remote abilities.\n");
|
||||
}
|
||||
|
||||
void DistributedSchedDumper::IllegalInput(std::string& result)
|
||||
{
|
||||
result.append("The arguments are illegal and you can enter '-h' for help.\n");
|
||||
}
|
||||
|
||||
void DistributedSchedDumper::ShowConnectRemoteAbility(std::string& result)
|
||||
{
|
||||
DistributedSchedService::GetInstance().DumpConnectInfo(result);
|
||||
}
|
||||
|
||||
bool DistributedSchedDumper::CanDump()
|
||||
{
|
||||
auto callingUid = IPCSkeleton::GetCallingUid();
|
||||
HILOGI("calling uid = %u", callingUid);
|
||||
if (callingUid != UID_ROOT) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
@ -132,6 +132,11 @@ int32_t DisconnectAbility()
|
||||
{
|
||||
return DistributedSchedService::GetInstance().DisconnectAbility();
|
||||
}
|
||||
|
||||
bool DistributedSchedDump(const std::vector<std::string>& args, std::string& result)
|
||||
{
|
||||
return DistributedSchedDumper::Dump(args, result);
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_SINGLE_INSTANCE(DistributedSchedService);
|
||||
@ -1643,23 +1648,6 @@ bool ConnectAbilitySession::IsSameCaller(const CallerInfo& callerInfo)
|
||||
callerInfo.callerType == callerInfo_.callerType);
|
||||
}
|
||||
|
||||
int32_t DistributedSchedService::Dump(int32_t fd, const std::vector<std::u16string>& args)
|
||||
{
|
||||
std::vector<std::string> argsInStr8;
|
||||
for (const auto& arg : args) {
|
||||
argsInStr8.emplace_back(Str16ToStr8(arg));
|
||||
}
|
||||
|
||||
std::string result;
|
||||
DistributedSchedDumper::Dump(argsInStr8, result);
|
||||
|
||||
if (!SaveStringToFd(fd, result)) {
|
||||
HILOGE("save to fd failed");
|
||||
return DMS_WRITE_FILE_FAILED_ERR;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
||||
void DistributedSchedService::DumpConnectInfo(std::string& info)
|
||||
{
|
||||
std::lock_guard<std::mutex> autoLock(distributedLock_);
|
||||
|
Loading…
Reference in New Issue
Block a user