• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 
17 #include "napi_env.h"
18 #include "calendar_log.h"
19 #include "calendar_env.h"
20 #include "ability.h"
21 #include "ability_context.h"
22 #include "context.h"
23 #include "napi_base_context.h"
24 #include "data_share_helper_manager.h"
25 #include "datashare_helper.h"
26 #include "datashare_predicates.h"
27 #include "accesstoken_kit.h"
28 
29 #include "ipc_skeleton.h"
30 
31 namespace OHOS::CalendarApi {
32 
GetContext(napi_env env,napi_value value)33 napi_status CalendarEnvNapi::GetContext(napi_env env, napi_value value)
34 {
35     bool isStageMode = false;
36     auto status = AbilityRuntime::IsStageContext(env, value, isStageMode);
37     if (status != napi_ok || !isStageMode) {
38         LOG_ERROR("No support FA Model; No support get calendarMgr in worker thread");
39         return napi_generic_failure;
40     }
41     m_context = OHOS::AbilityRuntime::GetStageModeContext(env, value);
42     if (m_context == nullptr) {
43         LOG_ERROR("GetStageModeContext contextRtm == nullptr.");
44         return napi_generic_failure;
45     }
46     return napi_ok;
47 }
48 
Init(napi_env env,napi_value value)49 void CalendarEnvNapi::Init(napi_env env, napi_value value)
50 {
51     LOG_INFO("CalendarEnvNapi Init.");
52     auto status = GetContext(env, value);
53     if (status != napi_ok) {
54         LOG_ERROR("CalendarEnvNapi::Init error");
55         return;
56     }
57     std::string bundleName = m_context->GetBundleName();
58     uint64_t tokenId = IPCSkeleton::GetSelfTokenID();
59     CalendarEnv::GetInstance().Init(bundleName, tokenId);
60 }
61 
getContext()62 std::shared_ptr<OHOS::AbilityRuntime::Context> CalendarEnvNapi::getContext()
63 {
64     return m_context;
65 }
66 };
67