• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 AMS_ABILITY_VISIBLE_TEST_PAGE_B2
17 #define AMS_ABILITY_VISIBLE_TEST_PAGE_B2
18 #include "stpageabilityevent.h"
19 #include <string>
20 #include <thread>
21 #include "ability_connect_callback_stub.h"
22 #include "ability_connect_callback_proxy.h"
23 #include "abs_shared_result_set.h"
24 #include "ability_loader.h"
25 #include "app_log_wrapper.h"
26 #include "completed_callback.h"
27 #include "data_ability_predicates.h"
28 #include "values_bucket.h"
29 #include "want_agent_helper.h"
30 
31 namespace OHOS {
32 namespace AppExecFwk {
33 
34 using AbilityConnectionStub = OHOS::AAFwk::AbilityConnectionStub;
35 using Uri = OHOS::Uri;
36 using CompletedCallback = OHOS::Notification::WantAgent::CompletedCallback;
37 using namespace OHOS::Notification::WantAgent;
38 
39 class AbilityConnectCallback : public AbilityConnectionStub {
40 public:
41     /**
42      * OnAbilityConnectDone, AbilityMs notify caller ability the result of connect.
43      *
44      * @param element,.service ability's ElementName.
45      * @param remoteObject,.the session proxy of service ability.
46      * @param resultCode, ERR_OK on success, others on failure.
47      */
OnAbilityConnectDone(const AppExecFwk::ElementName & element,const sptr<IRemoteObject> & remoteObject,int resultCode)48     void OnAbilityConnectDone(
49         const AppExecFwk::ElementName &element, const sptr<IRemoteObject> &remoteObject, int resultCode) override
50     {
51         APP_LOGI("AbilityConnectCallback::OnAbilityConnectDone:resultCode = %{public}d", resultCode);
52     }
53 
54     /**
55      * OnAbilityDisconnectDone, AbilityMs notify caller ability the result of disconnect.
56      *
57      * @param element,.service ability's ElementName.
58      * @param resultCode, ERR_OK on success, others on failure.
59      */
OnAbilityDisconnectDone(const AppExecFwk::ElementName & element,int resultCode)60     void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override
61     {
62         APP_LOGI("AbilityConnectCallback::OnAbilityDisconnectDone:resultCode = %{public}d", resultCode);
63     }
64 };
65 
66 class PendingWantCallback : public CompletedCallback {
67 private:
68     /* data */
69 public:
70     PendingWantCallback() = default;
71     ~PendingWantCallback() = default;
72 
OnSendFinished(const AAFwk::Want & want,int resultCode,const std::string & resultData,const AAFwk::WantParams & resultExtras)73     virtual void OnSendFinished(const AAFwk::Want &want, int resultCode, const std::string &resultData,
74         const AAFwk::WantParams &resultExtras) override
75     {
76         STPageAbilityEvent::PublishEvent(
77             STEventName::g_eventName, STEventName::g_defeventCode, STEventName::g_triggerWantAgentState);
78     }
79 };
80 
81 class AmsAbilityVisibleTestPageB2 : public Ability {
82 protected:
83     virtual void Init(const std::shared_ptr<AbilityInfo> &abilityInfo,
84         const std::shared_ptr<OHOSApplication> &application, std::shared_ptr<AbilityHandler> &handler,
85         const sptr<IRemoteObject> &token) override;
86     virtual void OnStart(const Want &want) override;
87     virtual void OnStop() override;
88     virtual void OnActive() override;
89     virtual void OnInactive() override;
90     virtual void OnBackground() override;
91     virtual void OnForeground(const Want &want) override;
92     virtual void OnNewWant(const Want &want) override;
93 
94 private:
95     void Clear();
96     void GetWantInfo(const Want &want);
97     std::string Split(std::string &str, std::string delim);
98     void GetAndTriggerWantAgent(std::string type, Want want, WantAgentConstant::OperationType operationType);
99 
100     std::string targetType_;
101     std::string targetBundle_;
102     std::string targetAbility_;
103     sptr<AbilityConnectCallback> stub_;
104     STPageAbilityEvent pageAbilityEvent;
105 };
106 }  // namespace AppExecFwk
107 }  // namespace OHOS
108 #endif  // AMS_ABILITY_VISIBLE_TEST_PAGE_B2