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 #include "ability_manager_client.h"
17 #include "mmi_log.h"
18 
19 #undef MMI_LOG_TAG
20 #define MMI_LOG_TAG "AbilityManagerClientStub"
21 
22 namespace OHOS {
23 namespace AAFwk {
24 std::shared_ptr<AbilityManagerClient> AbilityManagerClient::instance_ = nullptr;
25 
SetElementName(const std::string &deviceId, const std::string &bundleName, const std::string &abilityName, const std::string &moduleName)26 Want &Want::SetElementName(const std::string &deviceId, const std::string &bundleName,
27     const std::string &abilityName, const std::string &moduleName)
28 {
29     deviceId_ = deviceId;
30     bundleName_ = bundleName;
31     abilityName_ = abilityName;
32     moduleName_ = moduleName;
33 
34     return *this;
35 }
36 
SetAction(const std::string &action)37 Want &Want::SetAction(const std::string &action)
38 {
39     action_ = action;
40 
41     return *this;
42 }
43 
SetUri(const std::string &uri)44 Want &Want::SetUri(const std::string &uri)
45 {
46     uri_ = uri;
47 
48     return *this;
49 }
50 
SetType(const std::string &type)51 Want &Want::SetType(const std::string &type)
52 {
53     type_ = type;
54 
55     return *this;
56 }
57 
AddEntity(const std::string &entity)58 Want &Want::AddEntity(const std::string &entity)
59 {
60     entities_.push_back(entity);
61 
62     return *this;
63 }
64 
SetParam(const std::string &key, const std::string &value)65 Want &Want::SetParam(const std::string &key, const std::string &value)
66 {
67     params_.emplace(key, value);
68 
69     return *this;
70 }
71 
GetInstance()72 std::shared_ptr<AbilityManagerClient> AbilityManagerClient::GetInstance()
73 {
74     if (instance_ == nullptr) {
75         instance_ = std::make_shared<AbilityManagerClient> ();
76     }
77     return instance_;
78 }
79 
StartAbility(const Want &want, int32_t requestCode, int32_t userId)80 ErrCode AbilityManagerClient::StartAbility(const Want &want, int32_t requestCode, int32_t userId)
81 {
82     (void)want;
83     (void)requestCode;
84     (void)userId;
85 
86     MMI_HILOGI("StartAbility called");
87     if (callback_ != nullptr) {
88         callback_(want, err_);
89     }
90 
91     return err_;
92 }
93 
StartExtensionAbility(const Want &want, sptr<IRemoteObject> callerToken)94 ErrCode AbilityManagerClient::StartExtensionAbility(const Want &want, sptr<IRemoteObject> callerToken)
95 {
96     (void)want;
97     (void)callerToken;
98 
99     return ERR_OK;
100 }
101 
SetCallback(void (*cb)(const Want &want, ErrCode err))102 void AbilityManagerClient::SetCallback(void (*cb)(const Want &want, ErrCode err))
103 {
104     callback_ = cb;
105 }
106 
SetErrCode(ErrCode err)107 void AbilityManagerClient::SetErrCode(ErrCode err)
108 {
109     err_ = err;
110 }
111 } // namespace AAFwk
112 
113 namespace EventFwk {
114     const std::string CommonEventSupport::COMMON_EVENT_SCREEN_OFF = "usual.event.SCREEN_OFF";
115     const std::string CommonEventSupport::COMMON_EVENT_SCREEN_ON = "usual.event.SCREEN_ON";
116     const std::string CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED = "usual.event.SCREEN_LOCKED";
117     const std::string CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED = "usual.event.SCREEN_UNLOCKED";
118 } // namespace EventFwk
119 } // namespace OHOS
120