1 /* 2 * Copyright (C) 2023-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 /* 17 * This file is used as stub header for key_command_handler.cpp. 18 * It should re-define ability related methods for unit test. 19 */ 20 21 #ifndef ABILITY_MANAGER_CLIENT_STUB_H 22 #define ABILITY_MANAGER_CLIENT_STUB_H 23 24 #include <string> 25 #include <memory> 26 #include <vector> 27 #include <map> 28 #include <errors.h> 29 30 #include "iremote_object.h" 31 32 namespace OHOS { 33 namespace AAFwk { 34 35 constexpr int32_t DEFAULT_INVAL_VALUE = -1; 36 37 class Want { 38 public: 39 Want &SetElementName(const std::string &deviceId, const std::string &bundleName, 40 const std::string &abilityName, const std::string &moduleName = ""); 41 Want &SetAction(const std::string &action); 42 Want &SetUri(const std::string &uri); 43 Want &SetType(const std::string &type); 44 Want &AddEntity(const std::string &entity); 45 // Note: We use different SetParam() signature for test 46 Want &SetParam(const std::string &key, const std::string &value); 47 48 std::string bundleName_; 49 std::string abilityName_; 50 std::string action_; 51 std::string type_; 52 std::string deviceId_; 53 std::string uri_; 54 std::string moduleName_; 55 std::vector<std::string> entities_; 56 std::map<std::string, std::string> params_; 57 }; 58 59 class AbilityManagerClient { 60 public: AbilityManagerClient()61 AbilityManagerClient() 62 { 63 callback_ = nullptr; 64 err_ = ERR_OK; 65 } ~AbilityManagerClient()66 virtual ~AbilityManagerClient() {} 67 static std::shared_ptr<AbilityManagerClient> GetInstance(); 68 ErrCode StartAbility(const Want &want, int32_t requestCode = DEFAULT_INVAL_VALUE, 69 int32_t userId = DEFAULT_INVAL_VALUE); 70 ErrCode StartExtensionAbility(const Want &want, sptr<IRemoteObject> callerToken); 71 void SetCallback(void (*cb)(const Want &want, ErrCode err)); 72 void SetErrCode(ErrCode err); 73 74 private: 75 static std::shared_ptr<AbilityManagerClient> instance_; 76 void (*callback_)(const Want &want, ErrCode err); 77 ErrCode err_; 78 }; 79 80 } // namespace AAFwk 81 } // namespace OHOS 82 #endif // ABILITY_MANAGER_CLIENT_STUB_H 83