1 /* 2 * Copyright (c) 2024 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_CJ_ABILITY_DELEGATOR_FFI_H 17 #define OHOS_ABILITY_RUNTIME_CJ_ABILITY_DELEGATOR_FFI_H 18 19 #include <cstdint> 20 21 #include "ability_delegator_registry.h" 22 #include "cj_macro.h" 23 #include "ffi_remote_data.h" 24 25 using WantHandle = void*; 26 namespace OHOS { 27 namespace AbilityDelegatorCJ { 28 29 class CJAbilityDelegator : public FFI::FFIData { 30 public: CJAbilityDelegator(const std::shared_ptr<AppExecFwk::AbilityDelegator> & abilityDelegator)31 explicit CJAbilityDelegator(const std::shared_ptr<AppExecFwk::AbilityDelegator>& abilityDelegator) 32 : delegator_(abilityDelegator) {}; 33 34 int32_t StartAbility(const AAFwk::Want& want); 35 std::shared_ptr<AppExecFwk::ShellCmdResult> ExecuteShellCommand(const char* cmd, int64_t timeoutSec); 36 std::shared_ptr<AbilityRuntime::ApplicationContext> GetAppContext(); 37 void FinishTest(const char* msg, int64_t code); 38 39 private: 40 std::shared_ptr<AppExecFwk::AbilityDelegator> delegator_; 41 }; 42 43 class CJShellCmdResult : public FFI::FFIData { 44 public: CJShellCmdResult(std::shared_ptr<AppExecFwk::ShellCmdResult> shellCmdResult)45 explicit CJShellCmdResult(std::shared_ptr<AppExecFwk::ShellCmdResult> shellCmdResult) 46 : shellCmdResultr_(shellCmdResult) {}; 47 int32_t GetExitCode(); 48 std::string GetStdResult(); 49 std::string Dump(); 50 private: 51 std::shared_ptr<AppExecFwk::ShellCmdResult> shellCmdResultr_; 52 }; 53 54 extern "C" { 55 CJ_EXPORT int64_t FFIAbilityDelegatorRegistryGetAbilityDelegator(); 56 CJ_EXPORT int32_t FFIAbilityDelegatorStartAbility(int64_t id, WantHandle want); 57 CJ_EXPORT int32_t FFIAbilityDelegatorExecuteShellCommand(int64_t id, const char* cmd, int64_t timeoutSec); 58 CJ_EXPORT int32_t FFIGetExitCode(int64_t id); 59 CJ_EXPORT const char* FFIGetStdResult(int64_t id); 60 CJ_EXPORT const char* FFIDump(int64_t id); 61 CJ_EXPORT int32_t FFIAbilityDelegatorApplicationContext(int64_t id); 62 CJ_EXPORT void FFIAbilityDelegatorFinishTest(int64_t id, const char* msg, int64_t code); 63 }; 64 } 65 } 66 #endif // OHOS_ABILITY_RUNTIME_CJ_ABILITY_DELEGATOR_FFI_H