• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 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 "platform_adapter.h"
17 #include <cstdlib>
18 #include "acelite_config.h"
19 #if (defined(__LINUX__) || defined(__LITEOS_A__))
20 #include "ace_ability.h"
21 #endif
22 #include "ace_log.h"
23 #include "ace_version.h"
24 #include "js_fwk_common.h"
25 #include "product_adapter.h"
26 
27 namespace OHOS {
28 namespace ACELite {
PrintVersionTrace()29 void PrintVersionTrace()
30 {
31 #if (TARGET_SIMULATOR == 1)
32     // output version trace on simulator
33     HILOG_DEBUG(HILOG_MODULE_ACE, "ACELite version: %{public}s", ACEVersion::GetStr());
34     HILOG_DEBUG(HILOG_MODULE_ACE, "ACELite commit: %{public}s", ACEVersion::GetCommit());
35     HILOG_DEBUG(HILOG_MODULE_ACE, "ACELite build stamp: %{public}s", ACEVersion::GetTimeStamp());
36 #endif // TARGET_SIMULATOR
37 }
38 
SetEngineSnapshotMode(bool & mode)39 void SetEngineSnapshotMode(bool &mode)
40 {
41 #if (TARGET_SIMULATOR != 1)
42     mode = true;
43 #else
44     mode = false;
45 #endif
46 }
47 
SetEngineSnapshotModeManually(bool & mode)48 void SetEngineSnapshotModeManually(bool &mode)
49 {
50 #if (defined(__LINUX__) || defined(__LITEOS_A__))
51     // if not starting debugger, on real device, give a chance to use JS mode manually
52     mode = IsFileExisted(RUNTIME_MODE_FILE_PATH);
53 #elif (TARGET_SIMULATOR != 1)
54     mode = !(IsFileExisted(RUNTIME_MODE_FILE_PATH));
55 #endif
56 }
57 
Terminate(uint16_t token)58 void Terminate(uint16_t token)
59 {
60 #if (TARGET_SIMULATOR != 1) // no AMS support on PC simulator
61 #if (FEATURE_TERMINATE_ABILITY == 1)
62     ProductAdapter::SendTerminatingRequest(token, false);
63 #else
64     AceAbility::TerminateSelf();
65 #endif
66 #endif
67 }
68 
Srand(unsigned seed)69 void Srand(unsigned seed)
70 {
71 #if (TARGET_SIMULATOR == 1)
72     srand(seed);
73 #endif // TARGET_SIMULATOR
74 }
75 } // namespace ACELite
76 } // namespace OHOS
77