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 (defined (TARGET_SIMULATOR) && (TARGET_SIMULATOR == 1))
32 #if (defined (ACE_LITE_VERSION_JS_API) && (ACE_LITE_VERSION_JS_API == 1))
33 // output version trace on simulator
34 HILOG_DEBUG(HILOG_MODULE_ACE, "ACELite version: %{public}s", ACEVersion::GetStr());
35 HILOG_DEBUG(HILOG_MODULE_ACE, "ACELite commit: %{public}s", ACEVersion::GetCommit());
36 HILOG_DEBUG(HILOG_MODULE_ACE, "ACELite build stamp: %{public}s", ACEVersion::GetTimeStamp());
37 #endif // ACE_LITE_VERSION_JS_API
38 #endif // TARGET_SIMULATOR
39 }
40
SetEngineSnapshotMode(bool & mode)41 void SetEngineSnapshotMode(bool &mode)
42 {
43 #if (TARGET_SIMULATOR != 1)
44 mode = true;
45 #else
46 mode = false;
47 #endif
48 }
49
SetEngineSnapshotModeManually(bool & mode)50 void SetEngineSnapshotModeManually(bool &mode)
51 {
52 #if (defined(__LINUX__) || defined(__LITEOS_A__))
53 // if not starting debugger, on real device, give a chance to use JS mode manually
54 mode = IsFileExisted(RUNTIME_MODE_FILE_PATH);
55 #elif (TARGET_SIMULATOR != 1)
56 mode = !(IsFileExisted(RUNTIME_MODE_FILE_PATH));
57 #endif
58 }
59
Terminate(uint16_t token)60 void Terminate(uint16_t token)
61 {
62 #if (TARGET_SIMULATOR != 1)
63 #if (FEATURE_TERMINATE_ABILITY == 1)
64 ProductAdapter::SendTerminatingRequest(token, false);
65 #else
66 AceAbility::TerminateSelf();
67 #endif
68 #else
69 #ifdef _MINI_MULTI_TASKS_
70 ProductAdapter::SendTerminatingRequest(token, false);
71 #endif
72 #endif
73 }
74
Srand(unsigned seed)75 void Srand(unsigned seed)
76 {
77 #if (TARGET_SIMULATOR == 1)
78 srand(seed);
79 #endif // TARGET_SIMULATOR
80 }
81 } // namespace ACELite
82 } // namespace OHOS
83