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