1 /*
2 * Copyright (c) 2025 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 "ani_base_context.h"
17
18 namespace OHOS {
19 namespace AbilityRuntime {
IsStageContext(ani_env * env,ani_object object,ani_boolean & stageMode)20 ani_status IsStageContext(ani_env* env, ani_object object, ani_boolean& stageMode)
21 {
22 // arkTS 1.2 only supported stage mode
23 stageMode = true;
24 return ANI_OK;
25 }
26
GetStageModeContext(ani_env * env,ani_object object)27 std::shared_ptr<Context> GetStageModeContext(ani_env* env, ani_object object)
28 {
29 if (env == nullptr) {
30 TAG_LOGE(AAFwkTag::APPMGR, "env is nullptr");
31 return nullptr;
32 }
33 ani_long nativeContextLong;
34 ani_status status = env->Object_GetFieldByName_Long(object, "nativeContext", &nativeContextLong);
35 if (status != ANI_OK) {
36 TAG_LOGE(AAFwkTag::APPMGR, "Object_GetField_Long failed, status: %{public}d", status);
37 return nullptr;
38 }
39 auto weakContext = reinterpret_cast<std::weak_ptr<Context>*>(nativeContextLong);
40 return weakContext != nullptr ? weakContext->lock() : nullptr;
41 }
42 } // namespace AbilityRuntime
43 } // namespace OHOS
44