• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstdint>
17 #include <iostream>
18 
19 #include "options.h"
20 #include "simulator.h"
21 
22 constexpr int32_t PARAM_ONE = 1;
23 constexpr int32_t PARAM_TWO = 2;
24 constexpr int32_t PARAM_THREE = 3;
25 constexpr int32_t PARAM_FOUR = 4;
26 constexpr int32_t PARAM_FIVE = 5;
27 constexpr int32_t PARAM_SIX = 6;
28 constexpr int32_t PARAM_SEVEN = 7;
29 constexpr int32_t PARAM_EIGHT = 8;
30 constexpr int32_t PARAM_NINE = 9;
31 constexpr int32_t PARAM_TEN = 10;
32 constexpr int32_t PARAM_ELEVEN = 11;
33 constexpr int32_t PARAM_TWELVE = 12;
34 constexpr int32_t PARAM_THIRTEEN = 13;
35 constexpr int32_t PARAM_FOURTEEN = 14;
36 constexpr int32_t PARAM_FIFTEEN = 15;
37 constexpr int32_t PARAM_SIXTEEN = 16;
38 constexpr int32_t PARAM_SEVENTEEN = 17;
39 constexpr int32_t PARAM_EIGHTEEN = 18;
40 constexpr int32_t PARAM_NINETEEN = 19;
41 constexpr int32_t PARAM_TWENTY = 20;
42 constexpr int32_t PARAM_TWENTYONE = 21;
43 constexpr int32_t PARAM_TWENTYTWO = 22;
44 constexpr int32_t PARAM_TWENTYTHREE = 23;
45 constexpr int32_t PARAM_TWENTYFOUR = 24;
46 constexpr int32_t PARAM_TWENTYFIVE = 25;
47 constexpr int32_t PARAM_TWENTYSIX = 26;
48 constexpr int32_t PARAM_TWENTYSEVEN = 27;
49 constexpr int32_t PARAM_TWENTYEIGHT = 28;
50 
main(int32_t argc,const char * argv[])51 int32_t main(int32_t argc, const char *argv[])
52 {
53     if (argc < PARAM_TWENTYEIGHT) {
54         std::cout << "Insufficient parameters." << std::endl;
55         return 1;
56     }
57 
58     OHOS::AbilityRuntime::Options options;
59     options.bundleName = argv[PARAM_ONE];
60     options.moduleName = argv[PARAM_TWO];
61     options.modulePath = argv[PARAM_THREE];
62     options.resourcePath = argv[PARAM_FOUR];
63     options.debugPort = atoi(argv[PARAM_FIVE]);
64     options.assetPath = argv[PARAM_SIX];
65     options.systemResourcePath = argv[PARAM_SEVEN];
66     options.appResourcePath = argv[PARAM_EIGHT];
67     options.containerSdkPath = argv[PARAM_NINE];
68     options.url = argv[PARAM_TEN];
69     options.language = argv[PARAM_ELEVEN];
70     options.region = argv[PARAM_TWELVE];
71     options.script = argv[PARAM_THIRTEEN];
72     options.themeId = atoi(argv[PARAM_FOURTEEN]);
73     options.deviceWidth = atoi(argv[PARAM_FIFTEEN]);
74     options.deviceHeight = atoi(argv[PARAM_SIXTEEN]);
75     options.isRound = atoi(argv[PARAM_SEVENTEEN]);
76     options.compatibleVersion = atoi(argv[PARAM_EIGHTEEN]);
77     options.installationFree = atoi(argv[PARAM_NINETEEN]);
78     options.labelId = atoi(argv[PARAM_TWENTY]);
79     options.compileMode = argv[PARAM_TWENTYONE];
80     options.pageProfile = argv[PARAM_TWENTYTWO];
81     options.targetVersion = atoi(argv[PARAM_TWENTYTHREE]);
82     options.releaseType = argv[PARAM_TWENTYFOUR];
83     options.enablePartialUpdate = atoi(argv[PARAM_TWENTYFIVE]);
84     options.previewPath = argv[PARAM_TWENTYEIGHT];
85 
86     OHOS::AppExecFwk::HapModuleInfo hapModuleInfo;
87     hapModuleInfo.name = "entry";
88     hapModuleInfo.srcEntrance = argv[PARAM_TWENTYSEVEN];
89     options.hapModuleInfo = hapModuleInfo;
90 
91     OHOS::AppExecFwk::ApplicationInfo appInfo;
92     appInfo.name = "com.test.simulator";
93     options.applicationInfo = appInfo;
94 
95     OHOS::AppExecFwk::AbilityInfo abilityInfo;
96     abilityInfo.name = "EntryAbility";
97     options.abilityInfo = abilityInfo;
98 
99     OHOS::AppExecFwk::Configuration config;
100     config.AddItem(OHOS::AAFwk::GlobalConfigurationKey::SYSTEM_LANGUAGE, "testlanguage");
101     config.AddItem(OHOS::AAFwk::GlobalConfigurationKey::SYSTEM_COLORMODE, "light");
102     config.AddItem(OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DIRECTION, "vertical");
103     auto configuration = std::make_shared<OHOS::AppExecFwk::Configuration>(config);
104     options.configuration = configuration;
105 
106     auto simulator = OHOS::AbilityRuntime::Simulator::Create(options);
107     if (!simulator) {
108         std::cout << "Create Simulator failed." << std::endl;
109         return 1;
110     }
111 
112     std::string abilitySrcPath {argv[PARAM_TWENTYSIX]};
113     int64_t id = simulator->StartAbility(abilitySrcPath, [](int64_t abilityId) {});
114     if (id < 0) {
115         std::cout << "Start Ability failed." << std::endl;
116         return 1;
117     }
118 
119     config.AddItem(OHOS::AppExecFwk::ConfigurationInner::APPLICATION_DIRECTION, "horizontal");
120     simulator->UpdateConfiguration(config);
121 
122     simulator->TerminateAbility(id);
123     return 0;
124 }
125