mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 09:21:28 +00:00
!4980 remove obsolete tool: fm
Merge pull request !4980 from yangliang36/yl0315
This commit is contained in:
commit
3fea74faf1
@ -1,73 +0,0 @@
|
||||
# Copyright (c) 2021-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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/ability/ability_runtime/ability_runtime.gni")
|
||||
|
||||
config("tools_fm_config") {
|
||||
include_dirs = [
|
||||
"${ability_base_kits_path}/want/include",
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
"${ability_runtime_path}/tools/aa/include",
|
||||
"${ability_runtime_services_path}/common/include",
|
||||
"${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include",
|
||||
"include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_source_set("tools_fm_source_set") {
|
||||
sources = [
|
||||
"${ability_runtime_path}/tools/aa/src/shell_command.cpp",
|
||||
"src/fms_command.cpp",
|
||||
"src/main.cpp",
|
||||
]
|
||||
|
||||
defines = [ "AMS_LOG_TAG = \"FmsTool\"" ]
|
||||
|
||||
public_configs = [ ":tools_fm_config" ]
|
||||
|
||||
cflags = []
|
||||
if (target_cpu == "arm") {
|
||||
cflags += [ "-DBINDER_IPC_32BIT" ]
|
||||
}
|
||||
|
||||
deps = []
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_runtime:app_manager",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"bundle_framework:appexecfwk_core",
|
||||
"c_utils:utils",
|
||||
"form_fwk:form_manager",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_tools"
|
||||
}
|
||||
|
||||
ohos_executable("fm") {
|
||||
deps = [ ":tools_fm_source_set" ]
|
||||
|
||||
install_enable = true
|
||||
|
||||
subsystem_name = "ability"
|
||||
part_name = "ability_tools"
|
||||
}
|
||||
|
||||
group("tools_fm") {
|
||||
deps = [ ":fm" ]
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
/*
|
||||
* 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_ABILITY_RUNTIME_FMS_COMMAND_H
|
||||
#define OHOS_ABILITY_RUNTIME_FMS_COMMAND_H
|
||||
|
||||
#include "shell_command.h"
|
||||
#include "form_mgr_interface.h"
|
||||
#include "iremote_proxy.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
namespace {
|
||||
const std::string FM_TOOL_NAME = "fm";
|
||||
|
||||
const std::string FM_HELP_MSG = "usage: fm <command> <options>\n"
|
||||
"These are common fm commands list:\n"
|
||||
" help list available commands\n"
|
||||
" query query form info with options\n";
|
||||
|
||||
const std::string HELP_MSG_QUERY =
|
||||
"usage: fm query <options>\n"
|
||||
"options list:\n"
|
||||
" -h, --help list available commands\n"
|
||||
" -s, --storage query form storage info\n"
|
||||
" -n <bundle-name> query form info by a bundle name\n"
|
||||
" -i <form-id> query form info by a form id\n";
|
||||
|
||||
|
||||
const std::string HELP_MSG_NO_BUNDLE_PATH_OPTION =
|
||||
"error: you must specify a form id with '-1' or '--formid'.";
|
||||
|
||||
const std::string HELP_MSG_NO_BUNDLE_NAME_OPTION =
|
||||
"error: you must specify a bundle name with '-n' or '--name'.";
|
||||
|
||||
const std::string STRING_QUERY_FORM_INFO_OK = "query form info successfully.";
|
||||
const std::string STRING_QUERY_FORM_INFO_NG = "error: failed to query form info.";
|
||||
} // namespace
|
||||
|
||||
class FormMgrShellCommand : public OHOS::AAFwk::ShellCommand {
|
||||
public:
|
||||
FormMgrShellCommand(int argc, char* argv[]);
|
||||
~FormMgrShellCommand() override
|
||||
{}
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Create command map.
|
||||
*/
|
||||
ErrCode CreateCommandMap() override;
|
||||
/**
|
||||
* @brief Create message map.
|
||||
*/
|
||||
ErrCode CreateMessageMap() override;
|
||||
/**
|
||||
* @brief init.
|
||||
*/
|
||||
ErrCode init() override;
|
||||
/**
|
||||
* @brief Run help command.
|
||||
*/
|
||||
ErrCode RunAsHelpCommand();
|
||||
/**
|
||||
* @brief Run query form info command.
|
||||
*/
|
||||
ErrCode RunAsQueryCommand();
|
||||
|
||||
/**
|
||||
* @brief Query all of form storage infos.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t QueryStorageFormInfos();
|
||||
/**
|
||||
* @brief Query form infos by bundleName.
|
||||
* @param bundleName BundleName.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t QueryFormInfoByBundleName(const std::string& bundleName);
|
||||
/**
|
||||
* @brief Query form infos by form id.
|
||||
* @param formId The id of the form.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t QueryFormInfoByFormId(const std::int64_t formId);
|
||||
/**
|
||||
* @brief Handle command args.
|
||||
* @param optopt Command optopt.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t HandleUnknownOption(const char optopt);
|
||||
/**
|
||||
* @brief Handle command args.
|
||||
* @param option Command option.
|
||||
* @param bundleName BundleName.
|
||||
* @param formId The id of the form.
|
||||
* @param cmdFlag Command Flag.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t HandleNormalOption(const int option, std::string& bundleName, int64_t& formId, int32_t& cmdFlag);
|
||||
|
||||
/**
|
||||
* @brief Execute query form info command.
|
||||
* @param bundleName BundleName.
|
||||
* @param formId The id of the form.
|
||||
* @param cmdFlag Command Flag.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t ExecuteQuery(const std::string& bundleName, const int64_t formId, const int32_t cmdFlag);
|
||||
|
||||
/**
|
||||
* @brief Connect form manager service.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t ConnectFms();
|
||||
|
||||
bool WriteInterfaceToken(MessageParcel& data);
|
||||
int GetStringInfo(IFormMgr::Message code, MessageParcel& data, std::string& stringInfo);
|
||||
int SendTransactCmd(IFormMgr::Message code, MessageParcel& data, MessageParcel& reply);
|
||||
private:
|
||||
sptr<IRemoteObject> remoteObject_;
|
||||
};
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // OHOS_ABILITY_RUNTIME_FMS_COMMAND_H
|
@ -1,498 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-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 <cinttypes>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "appexecfwk_errors.h"
|
||||
#include "hilog_wrapper.h"
|
||||
#include "fms_command.h"
|
||||
#include "form_mgr_errors.h"
|
||||
#include "if_system_ability_manager.h"
|
||||
#include "ipc_skeleton.h"
|
||||
#include "iservice_registry.h"
|
||||
#include "string_ex.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
using namespace OHOS::AAFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AppExecFwk {
|
||||
namespace {
|
||||
const int COMMAND_QUERY_INVALID = -1;
|
||||
const int COMMAND_QUERY_STORAGE = 0;
|
||||
const int COMMAND_QUERY_NAME = 1;
|
||||
const int COMMAND_QUERY_ID = 2;
|
||||
|
||||
// const std::string BUNDLE_NAME_EMPTY = "";
|
||||
|
||||
const std::string SHORT_OPTIONS = "hsn:i:";
|
||||
const struct option LONG_OPTIONS[] = {
|
||||
{"help", no_argument, nullptr, 'h'},
|
||||
{"storage", no_argument, nullptr, 's'},
|
||||
{"bundle-name", required_argument, nullptr, 'n'},
|
||||
{"form-id", required_argument, nullptr, 'i'},
|
||||
{0, 0, 0, 0},
|
||||
};
|
||||
} // namespace
|
||||
|
||||
FormMgrShellCommand::FormMgrShellCommand(int argc, char* argv[]) : ShellCommand(argc, argv, FM_TOOL_NAME)
|
||||
{
|
||||
}
|
||||
ErrCode FormMgrShellCommand::init()
|
||||
{
|
||||
return ERR_OK;
|
||||
}
|
||||
/**
|
||||
* @brief Create command map.
|
||||
*/
|
||||
ErrCode FormMgrShellCommand::CreateCommandMap()
|
||||
{
|
||||
commandMap_ = {
|
||||
{"help", std::bind(&FormMgrShellCommand::RunAsHelpCommand, this)},
|
||||
{"query", std::bind(&FormMgrShellCommand::RunAsQueryCommand, this)},
|
||||
};
|
||||
|
||||
return OHOS::ERR_OK;
|
||||
}
|
||||
/**
|
||||
* @brief Create message map.
|
||||
*/
|
||||
ErrCode FormMgrShellCommand::CreateMessageMap()
|
||||
{
|
||||
messageMap_ = {
|
||||
// error + message
|
||||
{
|
||||
ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR,
|
||||
"error: fm query internal error.",
|
||||
},
|
||||
{
|
||||
ERR_APPEXECFWK_FORM_INVALID_PARAM,
|
||||
"error: fm query param error.",
|
||||
},
|
||||
{
|
||||
ERR_APPEXECFWK_FORM_PERMISSION_DENY,
|
||||
"error: fm query permission denied.",
|
||||
},
|
||||
{
|
||||
ERR_APPEXECFWK_FORM_NOT_EXIST_ID,
|
||||
"warning: fm query no form info.",
|
||||
},
|
||||
{
|
||||
ERR_APPEXECFWK_FORM_COMMON_CODE,
|
||||
"error: unknown.",
|
||||
},
|
||||
};
|
||||
|
||||
return OHOS::ERR_OK;
|
||||
}
|
||||
/**
|
||||
* @brief Run help command.
|
||||
*/
|
||||
ErrCode FormMgrShellCommand::RunAsHelpCommand()
|
||||
{
|
||||
resultReceiver_.append(FM_HELP_MSG);
|
||||
|
||||
return OHOS::ERR_OK;
|
||||
}
|
||||
/**
|
||||
* @brief Run query form info command.
|
||||
*/
|
||||
ErrCode FormMgrShellCommand::RunAsQueryCommand()
|
||||
{
|
||||
int32_t result = OHOS::ERR_OK;
|
||||
int32_t cmdFlag = COMMAND_QUERY_INVALID;
|
||||
int option = -1;
|
||||
int counter = 0;
|
||||
std::string bundleName = "";
|
||||
int64_t formId = 0;
|
||||
|
||||
while (true) {
|
||||
counter++;
|
||||
option = getopt_long(argc_, argv_, SHORT_OPTIONS.c_str(), LONG_OPTIONS, nullptr);
|
||||
HILOG_INFO("option: %{public}d, optopt: %{public}d, optind: %{public}d", option, optopt, optind);
|
||||
if (optind < 0 || optind > argc_) {
|
||||
return OHOS::ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < argc_; i++) {
|
||||
HILOG_INFO("argv_[%{public}d]: %{public}s", i, argv_[i]);
|
||||
}
|
||||
|
||||
if (option == -1) {
|
||||
if (counter == 1) {
|
||||
// When scanning the first argument
|
||||
if (strcmp(argv_[optind], cmd_.c_str()) == 0) {
|
||||
// 'fm query' with no option: fm query
|
||||
// 'fm query' with a wrong argument: fm query xxx
|
||||
HILOG_ERROR("'fm query' with no option.");
|
||||
resultReceiver_.append(HELP_MSG_NO_OPTION + "\n");
|
||||
result = OHOS::ERR_INVALID_VALUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (option == '?') {
|
||||
result = HandleUnknownOption(optopt);
|
||||
break;
|
||||
}
|
||||
|
||||
result = HandleNormalOption(option, bundleName, formId, cmdFlag);
|
||||
}
|
||||
|
||||
if (result == OHOS::ERR_OK) {
|
||||
result = ExecuteQuery(bundleName, formId, cmdFlag);
|
||||
} else {
|
||||
resultReceiver_.append(HELP_MSG_QUERY);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @brief Handle command args.
|
||||
* @param optopt Command optopt.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t FormMgrShellCommand::HandleUnknownOption(const char optopt)
|
||||
{
|
||||
int32_t result = OHOS::ERR_OK;
|
||||
switch (optopt) {
|
||||
case 'n':
|
||||
case 'i': {
|
||||
// 'fm query -n' with no argument: fm query -n
|
||||
// 'fm query --bundle-name' with no argument: fm query --bundle-name
|
||||
// 'fm query -i' with no argument: fm query -i
|
||||
// 'fm query --form-id' with no argument: fm query --form-id
|
||||
HILOG_ERROR("'fm query' %{public}s with no argument.", argv_[optind - 1]);
|
||||
resultReceiver_.append("error: option '");
|
||||
resultReceiver_.append(argv_[optind - 1]);
|
||||
resultReceiver_.append("' requires a value.\n");
|
||||
result = OHOS::ERR_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
case 0: {
|
||||
// 'fm query' with a unknown option: fm query --x
|
||||
// 'fm query' with a unknown option: fm query --xxx
|
||||
std::string unknownOption = "";
|
||||
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
|
||||
HILOG_ERROR("'fm query' with a unknown option: %{public}s", unknownOption.c_str());
|
||||
resultReceiver_.append(unknownOptionMsg);
|
||||
result = OHOS::ERR_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// 'fm query' with a unknown option: fm query -x
|
||||
// 'fm query' with a unknown option: fm query -xxx
|
||||
std::string unknownOption = "";
|
||||
std::string unknownOptionMsg = GetUnknownOptionMsg(unknownOption);
|
||||
HILOG_ERROR("'fm query' with a unknown option: %{public}s", unknownOption.c_str());
|
||||
resultReceiver_.append(unknownOptionMsg);
|
||||
result = OHOS::ERR_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @brief Handle command args.
|
||||
* @param option Command option.
|
||||
* @param bundleName BundleName.
|
||||
* @param formId The id of the form.
|
||||
* @param cmdFlag Command Flag.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t FormMgrShellCommand::HandleNormalOption(
|
||||
const int option, std::string& bundleName, int64_t& formId, int32_t& cmdFlag)
|
||||
{
|
||||
HILOG_INFO("%{public}s start, option: %{public}d", __func__, option);
|
||||
int32_t result = OHOS::ERR_OK;
|
||||
switch (option) {
|
||||
case 'h': {
|
||||
// 'fm query -h'
|
||||
// 'fm query --help'
|
||||
HILOG_INFO("'fm query' %{public}s", argv_[optind - 1]);
|
||||
result = OHOS::ERR_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
case 's': {
|
||||
// 'fm query -s'
|
||||
// 'fm query --storage'
|
||||
cmdFlag = COMMAND_QUERY_STORAGE;
|
||||
break;
|
||||
}
|
||||
case 'n': {
|
||||
// 'fm query -n <bundle-name>'
|
||||
// 'fm query --bundle-name <bundle-name>'
|
||||
if (optarg == nullptr) {
|
||||
resultReceiver_.append("error: option ");
|
||||
resultReceiver_.append("'-n'");
|
||||
resultReceiver_.append(" requires a value.\n");
|
||||
result = OHOS::ERR_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
cmdFlag = COMMAND_QUERY_NAME;
|
||||
bundleName = optarg;
|
||||
break;
|
||||
}
|
||||
case 'i': {
|
||||
// 'fm query -i <form-id> '
|
||||
// 'fm query --form-id <form-id> '
|
||||
if (optarg == nullptr) {
|
||||
resultReceiver_.append("error: option ");
|
||||
resultReceiver_.append("'-i'");
|
||||
resultReceiver_.append(" requires a value.\n");
|
||||
result = OHOS::ERR_INVALID_VALUE;
|
||||
break;
|
||||
}
|
||||
cmdFlag = COMMAND_QUERY_ID;
|
||||
formId = std::stoll(optarg);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
result = OHOS::ERR_INVALID_VALUE;
|
||||
HILOG_INFO("'fm query' invalid option.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
HILOG_INFO("%{public}s end, result: %{public}d", __func__, result);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @brief Execute query form info command.
|
||||
* @param bundleName BundleName.
|
||||
* @param formId The id of the form.
|
||||
* @param cmdFlag Command Flag.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t FormMgrShellCommand::ExecuteQuery(const std::string& bundleName, const int64_t formId, const int32_t cmdFlag)
|
||||
{
|
||||
HILOG_INFO("%{public}s start, bundleName: %{public}s, formId:%{public}" PRId64 "", __func__,
|
||||
bundleName.c_str(), formId);
|
||||
int32_t result = OHOS::ERR_OK;
|
||||
switch (cmdFlag) {
|
||||
case COMMAND_QUERY_STORAGE: {
|
||||
result = QueryStorageFormInfos();
|
||||
break;
|
||||
}
|
||||
case COMMAND_QUERY_NAME: {
|
||||
result = QueryFormInfoByBundleName(bundleName);
|
||||
break;
|
||||
}
|
||||
case COMMAND_QUERY_ID: {
|
||||
result = QueryFormInfoByFormId(formId);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
HILOG_INFO("'fm query' invalid command.");
|
||||
break;
|
||||
}
|
||||
HILOG_INFO("%{public}s end, cmdFlag: %{public}d", __func__, cmdFlag);
|
||||
}
|
||||
|
||||
if (result == OHOS::ERR_OK) {
|
||||
resultReceiver_ = STRING_QUERY_FORM_INFO_OK + "\n" + resultReceiver_;
|
||||
} else if (result == OHOS::ERR_APPEXECFWK_FORM_NOT_EXIST_ID) {
|
||||
resultReceiver_ = STRING_QUERY_FORM_INFO_OK + "\n";
|
||||
resultReceiver_.append(GetMessageFromCode(result));
|
||||
} else {
|
||||
resultReceiver_ = STRING_QUERY_FORM_INFO_NG + "\n";
|
||||
resultReceiver_.append(GetMessageFromCode(result));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @brief Query all of form storage infos.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t FormMgrShellCommand::QueryStorageFormInfos()
|
||||
{
|
||||
HILOG_INFO("%{public}s start", __func__);
|
||||
|
||||
int errCode = ConnectFms();
|
||||
if (errCode != OHOS::ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
std::string formInfos;
|
||||
MessageParcel data;
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
HILOG_ERROR("%{public}s, failed to write interface token", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
int result = GetStringInfo(IFormMgr::Message::FORM_MGR_STORAGE_FORM_INFOS, data, formInfos);
|
||||
if (result == ERR_OK) {
|
||||
resultReceiver_ = formInfos;
|
||||
} else {
|
||||
HILOG_ERROR("'fm query' failed to query form info.");
|
||||
}
|
||||
HILOG_INFO("%{public}s end, formInfo: %{public}s", __func__, resultReceiver_.c_str());
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @brief Query form infos by bundleName.
|
||||
* @param bundleName BundleName.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t FormMgrShellCommand::QueryFormInfoByBundleName(const std::string& bundleName)
|
||||
{
|
||||
HILOG_INFO("%{public}s start, bundleName: %{public}s", __func__, bundleName.c_str());
|
||||
|
||||
int errCode = ConnectFms();
|
||||
if (errCode != OHOS::ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
std::string formInfos;
|
||||
MessageParcel data;
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
HILOG_ERROR("%{public}s, failed to write interface token", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
if (!data.WriteString(bundleName)) {
|
||||
HILOG_ERROR("%{public}s, failed to write bundleName", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
int result = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_NAME, data, formInfos);
|
||||
if (result == ERR_OK) {
|
||||
HILOG_INFO("%{public}s, DumpFormInfoByBundleName success", __func__);
|
||||
resultReceiver_ = formInfos;
|
||||
} else {
|
||||
HILOG_ERROR("'fm query' failed to query form info.");
|
||||
}
|
||||
HILOG_INFO("%{public}s end, formInfo: %{public}s", __func__, resultReceiver_.c_str());
|
||||
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* @brief Query form infos by form id.
|
||||
* @param formId The id of the form.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t FormMgrShellCommand::QueryFormInfoByFormId(const std::int64_t formId)
|
||||
{
|
||||
HILOG_INFO("%{public}s start, formId: %{public}" PRId64 "", __func__, formId);
|
||||
|
||||
int errCode = ConnectFms();
|
||||
if (errCode != OHOS::ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
std::string formInfo;
|
||||
MessageParcel data;
|
||||
if (!WriteInterfaceToken(data)) {
|
||||
HILOG_ERROR("%{public}s, failed to write interface token", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteInt64(formId)) {
|
||||
HILOG_ERROR("%{public}s, failed to write formId", __func__);
|
||||
return ERR_APPEXECFWK_PARCEL_ERROR;
|
||||
}
|
||||
|
||||
int result = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_ID, data, formInfo);
|
||||
if (result == ERR_OK) {
|
||||
resultReceiver_ = formInfo;
|
||||
} else if (result == OHOS::ERR_APPEXECFWK_FORM_NOT_EXIST_ID) {
|
||||
HILOG_WARN("'fm query' no form info.");
|
||||
} else {
|
||||
HILOG_ERROR("'fm query' failed to query form info.");
|
||||
}
|
||||
HILOG_INFO("%{public}s end, formInfo: %{public}s", __func__, resultReceiver_.c_str());
|
||||
|
||||
return result;
|
||||
}
|
||||
bool FormMgrShellCommand::WriteInterfaceToken(MessageParcel& data)
|
||||
{
|
||||
if (!data.WriteInterfaceToken(IFormMgr::GetDescriptor())) {
|
||||
HILOG_ERROR("%{public}s, failed to write interface token", __func__);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
int FormMgrShellCommand::GetStringInfo(IFormMgr::Message code, MessageParcel& data, std::string& stringInfo)
|
||||
{
|
||||
int error;
|
||||
MessageParcel reply;
|
||||
error = SendTransactCmd(code, data, reply);
|
||||
if (error != ERR_OK) {
|
||||
return error;
|
||||
}
|
||||
|
||||
error = reply.ReadInt32();
|
||||
if (error != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s, failed to read reply result: %{public}d", __func__, error);
|
||||
return error;
|
||||
}
|
||||
std::vector<std::string> stringInfoList;
|
||||
if (!reply.ReadStringVector(&stringInfoList)) {
|
||||
HILOG_ERROR("%{public}s, failed to read string vector from reply", __func__);
|
||||
return false;
|
||||
}
|
||||
if (stringInfoList.empty()) {
|
||||
HILOG_INFO("%{public}s, No string info", __func__);
|
||||
return ERR_APPEXECFWK_FORM_NOT_EXIST_ID;
|
||||
}
|
||||
for (const auto& info : stringInfoList) {
|
||||
stringInfo += info;
|
||||
}
|
||||
HILOG_DEBUG("%{public}s, get string info success", __func__);
|
||||
return ERR_OK;
|
||||
}
|
||||
int FormMgrShellCommand::SendTransactCmd(IFormMgr::Message code, MessageParcel& data, MessageParcel& reply)
|
||||
{
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!remoteObject_) {
|
||||
HILOG_ERROR("%{public}s, failed to get remote object, cmd: %{public}d", __func__, code);
|
||||
return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED;
|
||||
}
|
||||
int32_t result = remoteObject_->SendRequest(static_cast<uint32_t>(code), data, reply, option);
|
||||
if (result != ERR_OK) {
|
||||
HILOG_ERROR("%{public}s, failed to SendRequest: %{public}d, cmd: %{public}d", __func__, result, code);
|
||||
return result;
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
/**
|
||||
* @brief Connect form manager service.
|
||||
* @return Returns ERR_OK on success, others on failure.
|
||||
*/
|
||||
int32_t FormMgrShellCommand::ConnectFms()
|
||||
{
|
||||
if (remoteObject_ != nullptr) {
|
||||
return OHOS::ERR_OK;
|
||||
}
|
||||
sptr<ISystemAbilityManager> systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
|
||||
if (systemManager == nullptr) {
|
||||
HILOG_ERROR("%{private}s:fail to get system ability manager", __func__);
|
||||
return ERR_APPEXECFWK_FORM_GET_FMS_FAILED;
|
||||
}
|
||||
remoteObject_ = systemManager->GetSystemAbility(FORM_MGR_SERVICE_ID);
|
||||
if (remoteObject_ == nullptr) {
|
||||
HILOG_ERROR("%{private}s:fail to connect FormMgrService", __func__);
|
||||
return ERR_APPEXECFWK_FORM_GET_FMS_FAILED;
|
||||
}
|
||||
|
||||
HILOG_INFO("%{public}s end, get fms proxy success", __func__);
|
||||
return OHOS::ERR_OK;
|
||||
}
|
||||
} // namespace AppExecFwk
|
||||
} // namespace OHOS
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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 "fms_command.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
OHOS::AppExecFwk::FormMgrShellCommand cmd(argc, argv);
|
||||
std::cout << cmd.ExecCommand();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user