• 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 #ifndef NOTIFICATION_GET_PARAM_H
16 #define NOTIFICATION_GET_PARAM_H
17 #include <memory>
18 #include <mutex>
19 #include <cstdint>
20 #include <vector>
21 
22 #include "ability.h"
23 #include "ability_handler.h"
24 #include "ability_manager.h"
25 #include "ability_manager_interface.h"
26 #include "ability_manager_service.h"
27 #include "data_uri_utils.h"
28 #include "element_name.h"
29 #include "event_runner.h"
30 #include "launcher_ability_info.h"
31 #include "launcher_service.h"
32 #include "uri.h"
33 #include "want.h"
34 
35 #ifdef PRINT_LOG
36 #undef PRINT_LOG
37 #endif
38 
39 #include "notification.h"
40 #include "notification_helper.h"
41 #include "notification_sorting_map.h"
42 #include "want_agent_helper.h"
43 
44 using Want = OHOS::AAFwk::Want;
45 namespace OHOS {
46 namespace Notification {
47 bool GetBoolParam();
48 uint8_t GetU8Param();
49 unsigned int GetUIntParam();
50 uint16_t GetU16Param();
51 uint32_t GetU32Param();
52 uint64_t GetU64Param();
53 int8_t GetS8Param();
54 int16_t GetS16Param();
55 int32_t GetS32Param();
56 int64_t GetS64Param();
57 char32_t GetChar32Param();
58 
59 short GetShortParam();
60 long GetLongParam();
61 int GetIntParam();
62 double GetDoubleParam();
63 float GetFloatParam();
64 char GetCharParam();
65 char *GetCharArryParam();
66 std::string GetStringParam();
67 std::vector<bool> GetBoolVectorParam();
68 std::vector<short> GetShortVectorParam();
69 std::vector<long> GetLongVectorParam();
70 std::vector<int> GetIntVectorParam();
71 std::vector<float> GetFloatVectorParam();
72 std::vector<double> GetDoubleVectorParam();
73 std::vector<char> GetCharVectorParam();
74 std::vector<char32_t> GetChar32VectorParam();
75 std::vector<std::string> GetStringVectorParam();
76 template <class T>
77 std::vector<T> GetUnsignVectorParam();
78 std::vector<int8_t> GetS8VectorParam();
79 std::vector<int16_t> GetS16VectorParam();
80 std::vector<int32_t> GetS32VectorParam();
81 std::vector<int64_t> GetS64VectorParam();
82 std::shared_ptr<Want> GetParamWant();
83 sptr<IRemoteObject> GetParamSptrRemote();
84 std::shared_ptr<OHOS::AppExecFwk::EventRunner> GetParamEventRunner();
85 std::shared_ptr<OHOS::AppExecFwk::Ability> GetParamAbility();
86 std::shared_ptr<OHOS::AAFwk::WantParams> GetParamWantParams();
87 OHOS::AppExecFwk::ApplicationFlag GetParamApplicationFlag();
88 OHOS::AppExecFwk::ApplicationInfo GetParamApplicationInfo();
89 OHOS::AppExecFwk::AbilityInfo GetParamAbilityInfo();
90 sptr<OHOS::AppExecFwk::IBundleStatusCallback> GetParamIBundleStatusCallback();
91 std::shared_ptr<OHOS::Notification::NotificationSorting> GetParamNotificationSorting();
92 std::vector<OHOS::Notification::NotificationSorting> GetParamNotificationSortingVector();
93 std::shared_ptr<OHOS::Notification::NotificationSortingMap> GetParamNotificationSortingMap();
94 std::shared_ptr<OHOS::Notification::NotificationSlot> GetParamNotificationSlot();
95 sptr<OHOS::Notification::NotificationSlot> GetParamNotificationSlotSptr();
96 OHOS::Notification::NotificationConstant::SlotType GetParamSlotType();
97 std::vector<sptr<OHOS::Notification::NotificationSlot>> GetParamNotificationSlotSptrVector();
98 std::vector<OHOS::Notification::NotificationSlot> GetParamNotificationSlotVector();
99 std::shared_ptr<OHOS::Notification::NotificationBundleOption> GetParamNotificationBundleOption();
100 std::shared_ptr<OHOS::Notification::NotificationRequest> GetParamNotificationRequest();
101 std::vector<sptr<OHOS::Notification::NotificationRequest>> GetParamNotificationRequestVector();
102 sptr<OHOS::Notification::NotificationSortingMap> GetParamNotificationSortingMapSptr();
103 OHOS::Notification::NotificationSlot::NotificationLevel GetParamNotificationLevel();
104 std::shared_ptr<OHOS::Notification::NotificationSubscriber> GetParamNotificationSubscriber();
105 std::shared_ptr<OHOS::Notification::NotificationSubscribeInfo> GetParamNotificationSubscribeInfo();
106 
107 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgentInfo> GetParamWantAgentInfo();
108 OHOS::AbilityRuntime::WantAgent::WantAgentConstant::OperationType GetParamOperationType();
109 OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags GetParamFlags();
110 std::vector<OHOS::AbilityRuntime::WantAgent::WantAgentConstant::Flags> GetParamFlagsVector();
111 
112 std::shared_ptr<OHOS::Notification::Notification> GetParamNotification();
113 sptr<OHOS::Notification::Notification> GetParamNotificationSptr();
114 std::vector<sptr<OHOS::Notification::Notification>> GetParamNotificationSptrVector();
115 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::PendingWant> GetParamPendingWant();
116 std::shared_ptr<OHOS::AbilityRuntime::AbilityRuntime::WantAgent::WantAgent> GetParamWantAgent();
117 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::CompletedCallback> GetParamCompletedCallback();
118 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::TriggerInfo> GetParamTriggerInfo();
119 std::shared_ptr<OHOS::AbilityRuntime::WantAgent::CancelListener> GetParamCancelListener();
120 
121 std::shared_ptr<OHOS::AppExecFwk::LauncherService> GetParamLauncherService();
122 std::vector<OHOS::AppExecFwk::LauncherAbilityInfo> GetParamLauncherAbilityInfoVector();
123 std::shared_ptr<OHOS::AppExecFwk::LauncherAbilityInfo> GetParamLauncherAbilityInfo();
124 std::vector<OHOS::AppExecFwk::LauncherShortcutInfo> GetParamLauncherShortcutInfoVector();
125 std::vector<OHOS::AppExecFwk::FormInfo> GetParamFormInfoVector();
126 std::vector<OHOS::AppExecFwk::ShortcutInfo> GetParamShortcutInfoVector();
127 std::vector<OHOS::AppExecFwk::ModuleUsageRecord> GetParamModuleUsageRecordVector();
128 sptr<OHOS::AppExecFwk::OnPermissionChangedCallback> GetParamOnPermissionChangedCallback();
129 
130 std::shared_ptr<OHOS::AppExecFwk::TaskDispatcher> GetParamTaskDispatcher();
131 std::shared_ptr<OHOS::AppExecFwk::BaseTaskDispatcher> GetParamBaseTaskDispatcher();
132 OHOS::AppExecFwk::TaskPriority GetParamTaskPriority();
133 std::shared_ptr<OHOS::AppExecFwk::Runnable> GetParamRunnable();
134 std::shared_ptr<OHOS::AppExecFwk::Group> GetParamGroup();
135 std::shared_ptr<OHOS::AppExecFwk::IteratableTask<long>> GetParamIteratableTask();
136 OHOS::Notification::NotificationConstant::SubscribeResult GetParamSubscribeResult();
137 OHOS::AppExecFwk::MissionInformation GetParamMissionInformation();
138 std::shared_ptr<OHOS::AppExecFwk::AbilityLifecycleCallbacks> GetParamAbilityLifecycleCallbacks();
139 std::shared_ptr<OHOS::AAFwk::IAbilityManager> GetParamIAbilityManager();
140 std::shared_ptr<OHOS::Notification::NotificationDoNotDisturbDate> GetParamNotificationDoNotDisturbDate();
141 OHOS::Notification::NotificationConstant::DoNotDisturbType GetParamDoNotDisturbType();
142 class TestRemoteObject : public IRemoteObject {
143 public:
144     /**
145      * @brief Default constructor used to construct.
146      */
147     TestRemoteObject();
148 
149     /**
150      * @brief Default deconstructor used to deconstruct.
151      */
152     ~TestRemoteObject();
153 
154     /**
155      * @brief Override GetObjectRefCount.
156      *
157      * @return Returns a fixed value of type int_32.
158      */
GetObjectRefCount()159     int32_t GetObjectRefCount() override
160     {
161         return 0;
162     }
163 
164     /**
165      * @brief Override SendRequest.
166      *
167      * @param code The uint32_t type input parameter.
168      * @param data The MessageParcel type input parameter.
169      * @param reply The MessageOption type input parameter.
170      * @param option The MessageOption type input parameter.
171      * @return Returns a fixed value of type int.
172      */
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)173     int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override
174     {
175         return 0;
176     }
177 
178     /**
179      * @brief Override IsProxyObject.
180      *
181      * @return Returns a fixed value of type bool.
182      */
IsProxyObject()183     bool IsProxyObject() const override
184     {
185         return true;
186     }
187 
188     /**
189      * @brief Override CheckObjectLegality.
190      *
191      * @return Returns a fixed value of type bool.
192      */
CheckObjectLegality()193     bool CheckObjectLegality() const override
194     {
195         return true;
196     }
197 
198     /**
199      * @brief Override AddDeathRecipient.
200      *
201      * @param recipient The DeathRecipient type point input parameter.
202      * @return Returns a fixed value of type bool.
203      */
AddDeathRecipient(const sptr<DeathRecipient> & recipient)204     bool AddDeathRecipient(const sptr<DeathRecipient> &recipient) override
205     {
206         return true;
207     }
208 
209     /**
210      * @brief Override RemoveDeathRecipient.
211      *
212      * @param recipient The DeathRecipient type point input parameter.
213      * @return Returns a fixed value of type bool.
214      */
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)215     bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient) override
216     {
217         return true;
218     }
219 
220     /**
221      * @brief Override Marshalling.
222      *
223      * @param parcel The Parcel type input parameter.
224      * @return Returns a fixed value of type bool.
225      */
Marshalling(Parcel & parcel)226     bool Marshalling(Parcel &parcel) const override
227     {
228         return true;
229     }
230 
231     /**
232      * @brief Override AsInterface.
233      *
234      * @return Returns a null pointer.
235      */
AsInterface()236     sptr<IRemoteBroker> AsInterface() override
237     {
238         return nullptr;
239     }
240 
241     /**
242      * @brief Override Dump.
243      *
244      * @param fd The int type input parameter.
245      * @param args The u16string type vector input parameter.
246      * @return Returns a fixed value of type int.
247      */
Dump(int fd,const std::vector<std::u16string> & args)248     int Dump(int fd, const std::vector<std::u16string> &args) override
249     {
250         return 0;
251     }
252 
253     /**
254      * @brief Override GetObjectDescriptor
255      *
256      * @return Returns a random value of type u16string.
257      */
GetObjectDescriptor()258     std::u16string GetObjectDescriptor() const
259     {
260         std::u16string descriptor = std::u16string();
261         return descriptor;
262     }
263 };
264 
265 class TestIBundleStatusCallback : public OHOS::AppExecFwk::IBundleStatusCallback {
266 public:
267     /**
268      * @brief Default constructor used to construct.
269      */
TestIBundleStatusCallback()270     TestIBundleStatusCallback()
271     {}
272 
273     /**
274      * @brief Override OnBundleStateChanged.
275      *
276      * @param installType The uint8_t type input parameter.
277      * @param resultCode The int32_t type input parameter.
278      * @param resultMsg The string type input parameter.
279      * @param bundleName The string type input parameter.
280      */
OnBundleStateChanged(const uint8_t installType,const int32_t resultCode,const std::string & resultMsg,const std::string & bundleName)281     void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode, const std::string &resultMsg,
282         const std::string &bundleName) override
283     {}
284 
285     /**
286      * @brief Default deconstructor used to deconstruct.
287      */
~TestIBundleStatusCallback()288     virtual ~TestIBundleStatusCallback()
289     {}
290 };
291 
292 class TestAnsSubscriber : public OHOS::Notification::NotificationSubscriber {
293 public:
294     /**
295      * @brief Default constructor used to create subscriber.
296      */
TestAnsSubscriber()297     TestAnsSubscriber()
298     {}
299 
300     /**
301      * @brief Default deconstructor used to deconstruct.
302      */
~TestAnsSubscriber()303     ~TestAnsSubscriber()
304     {}
305 
306     /**
307      * @brief Override OnConnected.
308      */
OnConnected()309     void OnConnected() override
310     {
311         std::cout << "TestAnsSubscriber OnConnected" << std::endl;
312         mutex.unlock();
313     }
314 
315     /**
316      * @brief Override OnDisconnected.
317      */
OnDisconnected()318     void OnDisconnected() override
319     {
320         std::cout << "TestAnsSubscriber OnDisconnected" << std::endl;
321         mutex.unlock();
322     }
323 
324     /**
325      * @brief Override OnDied.
326      */
OnDied()327     void OnDied() override
328     {}
329 
330     /**
331      * @brief Override OnUpdate.
332      *
333      * @param sortingMap The NotificationSortingMap type point input parameter.
334      */
OnUpdate(const std::shared_ptr<OHOS::Notification::NotificationSortingMap> & sortingMap)335     void OnUpdate(const std::shared_ptr<OHOS::Notification::NotificationSortingMap> &sortingMap) override
336     {}
337 
338     /**
339      * @brief Override OnDoNotDisturbDateChange.
340      *
341      * @param date The NotificationDoNotDisturbDate type point input parameter.
342      */
OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> & date)343     void OnDoNotDisturbDateChange(const std::shared_ptr<NotificationDoNotDisturbDate> &date) override
344     {}
345 
346     /**
347      * @brief Override OnCanceled.
348      *
349      * @param request The Notification type point input parameter.
350      * @param request The NotificationSortingMap type point input parameter.
351      * @param deleteReason The int type input parameter.
352      */
OnCanceled(const std::shared_ptr<OHOS::Notification::Notification> & request,const std::shared_ptr<OHOS::Notification::NotificationSortingMap> & sortingMap,int deleteReason)353     void OnCanceled(const std::shared_ptr<OHOS::Notification::Notification> &request,
354         const std::shared_ptr<OHOS::Notification::NotificationSortingMap> &sortingMap, int deleteReason) override
355     {}
356 
357     /**
358      * @brief Override OnConsumed.
359      *
360      * @param request The Notification type point input parameter.
361      */
OnConsumed(const std::shared_ptr<OHOS::Notification::Notification> & request)362     void OnConsumed(const std::shared_ptr<OHOS::Notification::Notification> &request) override
363     {}
364 
365     /**
366      * @brief Override OnConsumed.
367      *
368      * @param request The Notification type point input parameter.
369      * @param sortingMap The NotificationSortingMap type point input parameter.
370      */
OnConsumed(const std::shared_ptr<OHOS::Notification::Notification> & request,const std::shared_ptr<OHOS::Notification::NotificationSortingMap> & sortingMap)371     void OnConsumed(const std::shared_ptr<OHOS::Notification::Notification> &request,
372         const std::shared_ptr<OHOS::Notification::NotificationSortingMap> &sortingMap) override
373     {}
374 
375 public:
376     static std::mutex mutex;
377 };
378 
379 class TestCompletedCallback : public OHOS::AbilityRuntime::WantAgent::CompletedCallback {
OnSendFinished(const AAFwk::Want & want,int resultCode,const std::string & resultData,const AAFwk::WantParams & resultExtras)380     void OnSendFinished(const AAFwk::Want &want, int resultCode, const std::string &resultData,
381         const AAFwk::WantParams &resultExtras) override
382     {}
383 };
384 
385 class TestCancelListener : public OHOS::AbilityRuntime::WantAgent::CancelListener {
386 public:
387     /**
388      * @brief Override OnCancelled.
389      */
OnCancelled(int resultCode)390     void OnCancelled(int resultCode) override
391     {}
392 };
393 
394 class TestOnPermissionChangedCallback : public OHOS::AppExecFwk::OnPermissionChangedCallback {
395 public:
396     /**
397      * @brief Override OnChanged.
398      *
399      * @param uid Records the uid.
400      */
OnChanged(const int32_t uid)401     void OnChanged(const int32_t uid) override
402     {}
403 };
404 
405 class TestAbilityLifecycleCallbacks : public OHOS::AppExecFwk::AbilityLifecycleCallbacks {
406 public:
407     /**
408      * @brief Default constructor used to construct.
409      */
410     TestAbilityLifecycleCallbacks() = default;
411 
412     /**
413      * @brief Default deconstructor used to deconstruct.
414      */
415     virtual ~TestAbilityLifecycleCallbacks() = default;
416 
417     /**
418      * @brief Override OnAbilityStart.
419      *
420      * @param ability The ability to records the start state.
421      */
OnAbilityStart(const std::shared_ptr<Ability> & ability)422     virtual void OnAbilityStart(const std::shared_ptr<Ability> &ability)
423     {}
424 
425     /**
426      * @brief Override OnAbilityInactive.
427      *
428      * @param ability The ability to records the inactive state.
429      */
OnAbilityInactive(const std::shared_ptr<Ability> & ability)430     virtual void OnAbilityInactive(const std::shared_ptr<Ability> &ability)
431     {}
432 
433     /**
434      * @brief Override OnAbilityBackground.
435      *
436      * @param ability The ability to records the background state.
437      */
OnAbilityBackground(const std::shared_ptr<Ability> & ability)438     virtual void OnAbilityBackground(const std::shared_ptr<Ability> &ability)
439     {}
440 
441     /**
442      * @brief Override OnAbilityForeground.
443      *
444      * @param ability The ability to records the foreground state.
445      */
OnAbilityForeground(const std::shared_ptr<Ability> & ability)446     virtual void OnAbilityForeground(const std::shared_ptr<Ability> &ability)
447     {}
448 
449     /**
450      * @brief Override OnAbilityActive.
451      *
452      * @param ability The ability to records the active state.
453      */
OnAbilityActive(const std::shared_ptr<Ability> & ability)454     virtual void OnAbilityActive(const std::shared_ptr<Ability> &ability)
455     {}
456 
457     /**
458      * @brief Override OnAbilityStop.
459      *
460      * @param ability The ability to records the stop state.
461      */
OnAbilityStop(const std::shared_ptr<Ability> & ability)462     virtual void OnAbilityStop(const std::shared_ptr<Ability> &ability)
463     {}
464 
465     /**
466      * @brief Override OnAbilitySaveState.
467      *
468      * @param outState Output status.
469      */
OnAbilitySaveState(const OHOS::AppExecFwk::PacMap & outState)470     virtual void OnAbilitySaveState(const OHOS::AppExecFwk::PacMap &outState)
471     {}
472 };
473 class WantSender : public OHOS::AAFwk::WantSenderStub {
474 public:
475     /**
476      * @brief Override Send.
477      *
478      * @param senderInfo Sender information.
479      */
Send(OHOS::AAFwk::SenderInfo & senderInfo)480     void Send(OHOS::AAFwk::SenderInfo &senderInfo) override
481     {}
482 };
483 }  // namespace Notification
484 }  // namespace OHOS
485 #endif
486