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 #include "js_ability.h"
17
18 #include "log_print.h"
19
20 namespace OHOS {
21 namespace PreferencesJsKit {
22 namespace JSAbility {
GetContextMode(napi_env env,napi_value value)23 CONTEXT_MODE GetContextMode(napi_env env, napi_value value)
24 {
25 return STAGE;
26 }
27
GetContextInfo(napi_env env,napi_value value,const std::string & dataGroupId,ContextInfo & contextInfo)28 std::shared_ptr<JSError> GetContextInfo(napi_env env, napi_value value,
29 const std::string &dataGroupId, ContextInfo &contextInfo)
30 {
31 if (!dataGroupId.empty()) {
32 return std::make_shared<InnerError>(E_NOT_SUPPORTED);
33 }
34 auto stageContext = AbilityRuntime::Platform::GetStageModeContext(env, value);
35 if (stageContext == nullptr) {
36 LOG_ERROR("GetStageModeContext failed.");
37 return std::make_shared<InnerError>("The context is invalid.");
38 }
39 contextInfo.preferencesDir = stageContext->GetPreferencesDir();
40 return nullptr;
41 }
42 } // namespace JSAbility
43 } // namespace PreferencesJsKit
44 } // namespace OHOS
45