Support -D option for aa start command

Signed-off-by: zhaoyuan17 <zhaoyuan17@huawei.com>
This commit is contained in:
zhaoyuan17 2021-11-04 10:13:20 +00:00
parent 07ca2a13a6
commit 8cfbdbd2ce
7 changed files with 198 additions and 83 deletions

View File

@ -45,6 +45,7 @@ ohos_source_set("tools_aa_source_set") {
"${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base",
"${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:appexecfwk_core",
"${appexecfwk_path}/interfaces/innerkits/libeventhandler:libeventhandler",
"${innerkits_path}/base:base",
"${innerkits_path}/want:want",
"${services_path}/abilitymgr:abilityms",
"//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",

View File

@ -34,20 +34,20 @@ const std::string HELP_MSG = "usage: aa <command> <options>\n"
const std::string HELP_MSG_SCREEN =
"usage: aa screen <options>\n"
"options list:\n"
" -h, --help list available commands\n"
" -p, --power <state> power on or off with a state name\n";
" -h, --help list available commands\n"
" -p, --power <state> power on or off with a state name\n";
const std::string HELP_MSG_START =
"usage: aa start <options>\n"
"options list:\n"
" -h, --help list available commands\n"
" [-d <device-id>] -a <ability-name> -b <bundle-name> start ability with an element name\n";
" -h, --help list available commands\n"
" [-d <device-id>] -a <ability-name> -b <bundle-name> [-D] start ability with an element name\n";
const std::string HELP_MSG_STOP_SERVICE =
"usage: aa stop-service <options>\n"
"options list:\n"
" -h, --help list available commands\n"
" [-d <device-id>] -a <ability-name> -b <bundle-name> stop service with an element name\n";
" -h, --help list available commands\n"
" [-d <device-id>] -a <ability-name> -b <bundle-name> stop service with an element name\n";
const std::string HELP_MSG_DUMP = "usage: aa dump <options>\n"
"options list:\n"

View File

@ -13,18 +13,20 @@
* limitations under the License.
*/
#include "ability_command.h"
#include <getopt.h>
#include "ability_manager_client.h"
#include "hilog_wrapper.h"
#include "ohos/aafwk/base/bool_wrapper.h"
#include "ability_command.h"
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace AAFwk {
namespace {
const std::string SHORT_OPTIONS = "hd:a:b:p:s:";
const std::string SHORT_OPTIONS = "hd:a:b:p:s:D";
const struct option LONG_OPTIONS[] = {
{"help", no_argument, nullptr, 'h'},
{"device", required_argument, nullptr, 'd'},
@ -32,6 +34,7 @@ const struct option LONG_OPTIONS[] = {
{"bundle", required_argument, nullptr, 'b'},
{"power", required_argument, nullptr, 'p'},
{"setting", required_argument, nullptr, 's'},
{"debug", no_argument, nullptr, 'D'},
};
const std::string SHORT_OPTIONS_DUMP = "has:m:lud::e::";
@ -48,7 +51,11 @@ const struct option LONG_OPTIONS_DUMP[] = {
} // namespace
AbilityManagerShellCommand::AbilityManagerShellCommand(int argc, char *argv[]) : ShellCommand(argc, argv, TOOL_NAME)
{}
{
for (int i = 0; i < argc_; i++) {
HILOG_INFO("argv_[%{public}d]: %{public}s", i, argv_[i]);
}
}
ErrCode AbilityManagerShellCommand::CreateCommandMap()
{
@ -680,6 +687,8 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want &want, std::string &win
std::string bundleName = "";
std::string abilityName = "";
bool isDebugApp = false;
while (true) {
counter++;
@ -832,6 +841,12 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want &want, std::string &win
windowMode = optarg;
break;
}
case 'D': {
// 'aa start -D'
// debug app
isDebugApp = true;
break;
}
case 0: {
break;
}
@ -859,6 +874,13 @@ ErrCode AbilityManagerShellCommand::MakeWantFromCmd(Want &want, std::string &win
} else {
ElementName element(deviceId, bundleName, abilityName);
want.SetElement(element);
if (isDebugApp) {
WantParams wantParams;
wantParams.SetParam("debugApp", Boolean::Box(isDebugApp));
want.SetParams(wantParams);
}
}
}

View File

@ -36,6 +36,9 @@ int MockAbilityManagerStub::StartAbility(const Want &want, int requestCode)
return RESOLVE_APP_ERR;
}
auto isDebugApp = want.GetBoolParam("debugApp", false);
HILOG_INFO("isDebugApp: %{public}d", isDebugApp);
return ERR_OK;
}

View File

@ -69,7 +69,7 @@ void AaCommandStartSystemTest::TearDown()
/**
* @tc.number: Aa_Command_Start_SystemTest_0100
* @tc.name: ExecCommand
* @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name>" command.
* @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name> -D" command.
*/
HWTEST_F(AaCommandStartSystemTest, Aa_Command_Start_SystemTest_0100, Function | MediumTest | Level1)
{
@ -81,7 +81,7 @@ HWTEST_F(AaCommandStartSystemTest, Aa_Command_Start_SystemTest_0100, Function |
// start the page ability
std::string command = "aa start -d " + STRING_DEVICE_NAME + " -a " + STRING_PAGE_ABILITY_NAME + " -b " +
STRING_PAGE_ABILITY_BUNDLE_NAME;
STRING_PAGE_ABILITY_BUNDLE_NAME + " -D";
std::string commandResult = ToolSystemTest::ExecuteCommand(command);
EXPECT_EQ(commandResult, STRING_START_ABILITY_OK + "\n");

View File

@ -75,6 +75,8 @@ void AaCommandStartTest::MakeMockObjects() const
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0100, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0100");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -93,6 +95,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0100, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0200, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0200");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -112,6 +116,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0200, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0300, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0300");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -131,6 +137,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0300, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0400, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0400");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -150,6 +158,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0400, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0500, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0500");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -169,6 +179,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0500, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0600, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0600");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -188,6 +200,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0600, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0700, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0700");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -207,6 +221,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0700, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0800, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0800");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -226,6 +242,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0800, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_0900, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_0900");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -245,6 +263,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_0900, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1000, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1000");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -266,6 +286,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1000, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1100, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1100");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -287,6 +309,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1100, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1200, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1200");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -309,6 +333,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1200, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1300, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1300");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -330,6 +356,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1300, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1400, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1400");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -352,6 +380,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1400, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1500, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1500");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -375,6 +405,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1500, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1600, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1600");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -399,6 +431,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1600, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1700, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1700");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -418,6 +452,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1700, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1800, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1800");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -439,6 +475,8 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1800, Function | MediumTest | Leve
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_1900, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_1900");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -457,10 +495,37 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_1900, Function | MediumTest | Leve
/**
* @tc.number: Aa_Command_Start_2000
* @tc.name: ExecCommand
* @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name>" command.
* @tc.desc: Verify the "aa start -a <ability-name> -b <bundle-name> -D" command.
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2000, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2000");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
(char *)"-a",
(char *)STRING_ABILITY_NAME.c_str(),
(char *)"-b",
(char *)STRING_BUNDLE_NAME.c_str(),
(char *)"-D",
(char *)"",
};
int argc = sizeof(argv) / sizeof(argv[0]) - 1;
AbilityManagerShellCommand cmd(argc, argv);
EXPECT_EQ(cmd.ExecCommand(), STRING_START_ABILITY_OK + "\n");
}
/**
* @tc.number: Aa_Command_Start_2100
* @tc.name: ExecCommand
* @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name>" command.
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2100, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2100");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),
@ -479,12 +544,14 @@ HWTEST_F(AaCommandStartTest, Aa_Command_Start_2000, Function | MediumTest | Leve
}
/**
* @tc.number: Aa_Command_Start_2100
* @tc.number: Aa_Command_Start_2200
* @tc.name: ExecCommand
* @tc.desc: Verify the "aa start -d <device-id> -a <ability-name> -b <bundle-name>" command.
*/
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2100, Function | MediumTest | Level1)
HWTEST_F(AaCommandStartTest, Aa_Command_Start_2200, Function | MediumTest | Level1)
{
HILOG_INFO("Aa_Command_Start_2200");
char *argv[] = {
(char *)TOOL_NAME.c_str(),
(char *)cmd_.c_str(),

View File

@ -16,77 +16,99 @@
import { AsyncCallback } from './basic';
declare namespace zlib {
// Zlib library constant definition
export enum FlushType {
FLUSH_TYPE_NO_FLUSH = 0,
FLUSH_TYPE_PARTIAL_FLUSH = 1,
FLUSH_TYPE_SYNC_FLUSH = 2,
FLUSH_TYPE_FULL_FLUSH = 3,
FLUSH_TYPE_FINISH = 4,
FLUSH_TYPE_BLOCK = 5,
FLUSH_TYPE_TREES = 6
}
/**
* @name ErrorCode
* @since 7
* @SysCap SystemCapability.Appexecfwk
* @import NA
* @permission NA
* @devices phone, tablet, tv, wearable, car
*/
export enum ErrorCode {
ERROR_CODE_OK = 0,
ERROR_CODE_ERRNO = -1
}
// The return code of the compression and decompression function.
// A negative number indicates an error and a positive number indicates a normal event
// enum ErrorCode
export enum ErrorCode {
ERROR_CODE_OK = 0,
ERROR_CODE_STREAM_END = 1,
ERROR_CODE_NEED_DICT = 2,
ERROR_CODE_ERRNO = -1,
ERROR_CODE_STREAM_ERROR = -2,
ERROR_CODE_DATA_ERROR = -3,
ERROR_CODE_MEM_ERROR = -4,
ERROR_CODE_BUF_ERROR = -5,
ERROR_CODE_VERSION_ERROR = -6
}
// enum CompressLevel
export enum CompressLevel {
COMPRESS_LEVEL_NO_COMPRESSION = 0,
COMPRESS_LEVEL_BEST_SPEED = 1,
COMPRESS_LEVEL_BEST_COMPRESSION = 9,
COMPRESS_LEVEL_DEFAULT_COMPRESSION = -1
}
/**
* @name CompressLevel
* @since 7
* @SysCap SystemCapability.Appexecfwk
* @import NA
* @permission NA
* @devices phone, tablet, tv, wearable, car
*/
export enum CompressLevel {
COMPRESS_LEVEL_NO_COMPRESSION = 0,
COMPRESS_LEVEL_BEST_SPEED = 1,
COMPRESS_LEVEL_BEST_COMPRESSION = 9,
COMPRESS_LEVEL_DEFAULT_COMPRESSION = -1
}
// enum CompressStrategy
export enum CompressStrategy {
COMPRESS_STRATEGY_DEFAULT_STRATEGY = 0,
COMPRESS_STRATEGY_FILTERED = 1,
COMPRESS_STRATEGY_HUFFMAN_ONLY = 2,
COMPRESS_STRATEGY_RLE = 3,
COMPRESS_STRATEGY_FIXED = 4
}
/**
* @name CompressStrategy
* @since 7
* @SysCap SystemCapability.Appexecfwk
* @import NA
* @permission NA
* @devices phone, tablet, tv, wearable, car
*/
export enum CompressStrategy {
COMPRESS_STRATEGY_DEFAULT_STRATEGY = 0,
COMPRESS_STRATEGY_FILTERED = 1,
COMPRESS_STRATEGY_HUFFMAN_ONLY = 2,
COMPRESS_STRATEGY_RLE = 3,
COMPRESS_STRATEGY_FIXED = 4
}
// enum MemLevel
export enum MemLevel {
MEM_LEVEL_MIN_MEMLEVEL = 1,
MEM_LEVEL_DEFAULT_MEMLEVEL = 8,
MEM_LEVEL_MAX_MEMLEVEL = 9
}
/**
* @name MemLevel
* @since 7
* @SysCap SystemCapability.Appexecfwk
* @import NA
* @permission NA
* @devices phone, tablet, tv, wearable, car
*/
export enum MemLevel {
MEM_LEVEL_MIN = 1,
MEM_LEVEL_MAX = 9,
MEM_LEVEL_DEFAULT = 8
}
// zip options
interface Options {
flush?: FlushType; // corresponding zlib library macro
finishFlush?: FlushType; // corresponding zlib library macro #define Z_FINISH 4
chunkSize?: number; // Buffer size>64
level?: CompressLevel; // Compression level. The compression level is a number from 0 to 9.
// 0 has the fastest compression speed (compression process), 9 has the slowest compression speed,
// the largest compression rate, and 0 does not compress.
memLevel?: MemLevel; // How much memory should be allocated for the specified internal compression state.
// Memlevel = 1 uses the minimum memory, but it is very slow, reducing the compression ratio; Memlevel = 9 uses the maximum memory to get the best speed. The default value is 8.
strategy?: CompressStrategy; // CompressStrategy
dictionary?: ArrayBuffer; // deflate/inflate only, empty dictionary by default
}
// The interface for compressing the specified file. There is only one callback callback interface
function zipFile(inFile:string, outFile:string, options: Options, callback: AsyncCallback<void>): void;
function zipFile(inFile:string, outFile:string, options: Options): Promise<number>;
/**
* @name Options
* @since 7
* @SysCap SystemCapability.Appexecfwk
* @import NA
* @permission NA
* @devices phone, tablet, tv, wearable, car
*/
interface Options {
level?: CompressLevel;
memLevel?: MemLevel;
strategy?: CompressStrategy;
}
// The interface for decompressing the specified file. There is only one callback callback interface
function unzipFile(inFile:string, outFile:string, options: Options, callback: AsyncCallback<void>): void;
function unzipFile(inFile:string, outFile:string, options: Options): Promise<number>;
/**
* Compress the specified file.
*
* @devices phone, tablet, tv, wearable, car
* @since 7
* @SysCap SystemCapability.Appexecfwk
* @param inFile Indicates the path of the file to be compressed.
* @param outFile Indicates the path of the output compressed file.
* @return Returns error code.
*/
function zipFile(inFile:string, outFile:string, options: Options): Promise<void>;
/**
* Decompress the specified file.
*
* @devices phone, tablet, tv, wearable, car
* @since 7
* @SysCap SystemCapability.Appexecfwk
* @param inFile Indicates the path of the file to be decompressed.
* @param outFile Indicates the path of the decompressed file.
* @return Returns error code.
*/
function unzipFile(inFile:string, outFile:string, options: Options): Promise<void>;
}