1 /* 2 * Copyright (c) 2022 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 #ifndef OHOS_ABILITY_RUNTIME_JS_NAPI_COMMON_ABILITY_H 17 #define OHOS_ABILITY_RUNTIME_JS_NAPI_COMMON_ABILITY_H 18 #include "ability_connect_callback_stub.h" 19 #include "ability_info.h" 20 #include "ability_manager_errors.h" 21 #include "application_info.h" 22 #include "feature_ability_common.h" 23 #include "js_runtime_utils.h" 24 25 namespace OHOS { 26 namespace AppExecFwk { 27 class JsNapiCommon { 28 public: 29 JsNapiCommon(); 30 virtual ~JsNapiCommon() = default; 31 32 struct JsPermissionOptions { 33 bool uidFlag = false; 34 bool pidFlag = false; 35 int32_t uid = 0; 36 int32_t pid = 0; 37 }; 38 39 struct JsApplicationInfo { 40 ApplicationInfo appInfo; 41 }; 42 43 struct JsBundleName { 44 std::string name = ""; 45 }; 46 typedef JsBundleName JsProcessName; 47 typedef JsBundleName JsCallingBundleName; 48 typedef JsBundleName JsOrCreateLocalDir; 49 typedef JsBundleName JsFilesDir; 50 typedef JsBundleName JsCacheDir; 51 typedef JsBundleName JsCtxAppType; 52 typedef JsBundleName JsOrCreateDistributedDir; 53 typedef JsBundleName JsAppType; 54 55 struct JsElementName { 56 std::string deviceId = ""; 57 std::string bundleName = ""; 58 std::string abilityName = ""; 59 std::string uri = ""; 60 std::string shortName = ""; 61 }; 62 63 struct JsProcessInfo { 64 std::string processName = ""; 65 pid_t pid = 0; 66 }; 67 68 struct JsConfigurations { 69 bool status; 70 }; 71 typedef JsConfigurations JsDrawnCompleted; 72 73 struct JsHapModuleInfo { 74 HapModuleInfo hapModInfo; 75 }; 76 77 struct JsAbilityInfoInfo { 78 AbilityInfo abilityInfo; 79 }; 80 81 struct JsWant { 82 Want want; 83 }; 84 85 NativeValue* JsConnectAbility(NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 86 NativeValue* JsDisConnectAbility(NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 87 88 sptr<NAPIAbilityConnection> BuildWant(const Want &want, int64_t &id); 89 void ChangeAbilityConnection(napi_ref *callbackArray, const napi_env env, const napi_value &arg1); 90 NativeValue* JsGetContext(NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 91 NativeValue* JsGetFilesDir(NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 92 NativeValue* JsIsUpdatingConfigurations( 93 NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 94 NativeValue* JsPrintDrawnCompleted(NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 95 NativeValue* JsGetCacheDir(NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 96 NativeValue* JsGetCtxAppType(NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 97 NativeValue* JsGetCtxHapModuleInfo(NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 98 NativeValue* JsGetAppVersionInfo(NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 99 NativeValue* JsGetApplicationContext( 100 NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 101 NativeValue* JsGetCtxAbilityInfo(NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 102 NativeValue* JsGetOrCreateDistributedDir( 103 NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 104 NativeValue* JsGetDisplayOrientation( 105 NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 106 NativeValue* JsGetWant(NativeEngine &engine, NativeCallbackInfo &info, const AbilityType abilityType); 107 108 NativeValue* CreateProcessInfo(NativeEngine &engine, const std::shared_ptr<JsProcessInfo> &processInfo); 109 NativeValue* CreateElementName(NativeEngine &engine, const std::shared_ptr<JsElementName> &elementName); 110 NativeValue* CreateHapModuleInfo(NativeEngine &engine, const std::shared_ptr<JsHapModuleInfo> &hapModInfo); 111 NativeValue* CreateModuleInfo(NativeEngine &engine, const ModuleInfo &modInfo); 112 NativeValue* CreateModuleInfos(NativeEngine &engine, const std::vector<ModuleInfo> &moduleInfos); 113 NativeValue* CreateAppInfo(NativeEngine &engine, const ApplicationInfo &appInfo); 114 NativeValue* CreateAppInfo(NativeEngine &engine, const std::shared_ptr<JsApplicationInfo> &appInfo); 115 NativeValue* CreateAbilityInfo(NativeEngine &engine, const AbilityInfo &abilityInfo); 116 NativeValue* CreateAbilityInfo(NativeEngine &engine, const std::shared_ptr<JsAbilityInfoInfo> &abilityInfo); 117 NativeValue* CreateAbilityInfos(NativeEngine &engine, const std::vector<AbilityInfo> &abilityInfos); 118 NativeValue* CreateAppVersionInfo(NativeEngine &engine, const std::shared_ptr<JsApplicationInfo> &appInfo); 119 NativeValue* CreateWant(NativeEngine &engine, const std::shared_ptr<JsWant> &want); 120 bool CheckAbilityType(const AbilityType typeWant); 121 bool UnwarpVerifyPermissionParams(NativeEngine &engine, NativeCallbackInfo &info, JsPermissionOptions &options); 122 bool GetStringsValue(NativeEngine &engine, NativeValue *object, std::vector<std::string> &strList); 123 bool GetPermissionOptions(NativeEngine &engine, NativeValue *object, JsPermissionOptions &options); 124 std::string ConvertErrorCode(int32_t errCode); 125 126 Ability *ability_; 127 }; 128 } // namespace AppExecFwk 129 } // namespace OHOS 130 #endif // OHOS_ABILITY_RUNTIME_JS_NAPI_COMMON_ABILITY_H