• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.platform.helpers;
18 
19 import android.app.Notification;
20 import android.support.test.uiautomator.BySelector;
21 import android.support.test.uiautomator.Direction;
22 import android.support.test.uiautomator.UiObject2;
23 
24 import androidx.annotation.Nullable;
25 
26 /** An App Helper interface for the Notification. */
27 public interface INotificationHelper extends IAppHelper {
28 
29     String UI_PACKAGE_NAME_SYSUI = "com.android.systemui";
30     String UI_PACKAGE_NAME_ANDROID = "android";
31     String UI_NOTIFICATION_ID = "status_bar_latest_event_content";
32     String NOTIFICATION_TITLE_TEXT = "TEST NOTIFICATION";
33     String NOTIFICATION_CONTENT_TEXT = "Test notification content";
34     String NOTIFICATION_BIG_TEXT =
35             "lorem ipsum dolor sit amet\n"
36                     + "lorem ipsum dolor sit amet\n"
37                     + "lorem ipsum dolor sit amet\n"
38                     + "lorem ipsum dolor sit amet";
39     String NOTIFICATION_CHANNEL_NAME = "Test Channel";
40     String EXPAND_BUTTON_ID = "expand_button";
41     String BUBBLE_BUTTON = "bubble_button";
42     String APP_ICON_ID = "icon";
43 
44     /**
45      * Setup expectations: Notification shade opened.
46      *
47      * <p>Opens a notification from notification shade.
48      *
49      * @param index The index of the notification to open.
50      */
openNotificationbyIndex(int index)51     default void openNotificationbyIndex(int index) {
52         throw new UnsupportedOperationException("Not yet implemented.");
53     }
54 
55     /**
56      * Setup Expectations: None
57      *
58      * <p>Posts a number of notifications to the device. Successive calls to this should post new
59      * notifications to those previously posted. Note that this may fail if the helper has surpassed
60      * the system-defined limit for per-package notifications.
61      *
62      * @param count The number of notifications to post.
63      */
postNotifications(int count)64     default void postNotifications(int count) {
65         throw new UnsupportedOperationException("Not yet implemented.");
66     }
67 
68     /**
69      * Setup Expectations: Shade is open
70      *
71      * <p>Posts a notification using {@link android.app.Notification.BigTextStyle}.
72      *
73      * @param pkg App to launch, when clicking on notification.
74      */
postBigTextNotification(@ullable String pkg)75     default UiObject2 postBigTextNotification(@Nullable String pkg) {
76         throw new UnsupportedOperationException("Not yet implemented.");
77     }
78 
79     /**
80      * Setup Expectations: Shade is open
81      *
82      * <p>Posts a notification using {@link android.app.Notification.BigPictureStyle}.
83      *
84      * @param pkg App to launch, when clicking on notification.
85      */
postBigPictureNotification(String pkg)86     default UiObject2 postBigPictureNotification(String pkg) {
87         throw new UnsupportedOperationException("Not yet implemented.");
88     }
89 
90     /**
91      * Setup Expectations: Shade is open
92      *
93      * <p>Posts a notification using {@link android.app.Notification.MessagingStyle}.
94      *
95      * @param pkg App to launch, when clicking on notification.
96      */
postMessagingStyleNotification(String pkg)97     default UiObject2 postMessagingStyleNotification(String pkg) {
98         throw new UnsupportedOperationException("Not yet implemented.");
99     }
100 
101     /**
102      * Setup Expectations: Shade is open
103      *
104      * <p>Posts a bubble notification. This notification is associated with a conversation shortcut,
105      * a BubbleMetadata, and in {@link android.app.Notification.MessagingStyle}.
106      *
107      * @param senderName Name of notification sender.
108      * @param count How many bubble notifications to send.
109      */
postBubbleNotification(String senderName, int count)110     default void postBubbleNotification(String senderName, int count) {
111         throw new UnsupportedOperationException("Not yet implemented.");
112     }
113 
114     /**
115      * Return notification if found by text.
116      *
117      * @param text Text that notification contains.
118      */
getNotificationByText(String text)119     default UiObject2 getNotificationByText(String text) {
120         throw new UnsupportedOperationException("Not yet implemented.");
121     }
122 
123     /**
124      * Setup Expectations: Shade is open
125      *
126      * <p>Posts a conversation notification. This notification is associated with a conversation
127      * shortcut and in {@link android.app.Notification.MessagingStyle}.
128      *
129      * @param pkg App to launch, when clicking on notification.
130      */
postConversationNotification(String pkg)131     default UiObject2 postConversationNotification(String pkg) {
132         throw new UnsupportedOperationException("Not yet implemented.");
133     }
134 
135     /**
136      * Setup Expectations: None
137      *
138      * <p>Posts a number of notifications to the device with a package to launch. Successive calls
139      * to this should post new notifications in addition to those previously posted. Note that this
140      * may fail if the helper has surpassed the system-defined limit for per-package notifications.
141      *
142      * @param count The number of notifications to post.
143      * @param pkg The application that will be launched by notifications.
144      */
postNotifications(int count, String pkg)145     default void postNotifications(int count, String pkg) {
146         throw new UnsupportedOperationException("Not yet implemented.");
147     }
148 
149     /**
150      * Setup Expectations: None
151      *
152      * <p>Posts a number of notifications to the device with a package to launch. Successive calls
153      * to this should post new notifications in addition to those previously posted. Note that this
154      * may fail if the helper has surpassed the system-defined limit for per-package notifications.
155      *
156      * @param count The number of notifications to post.
157      * @param pkg The application that will be launched by notifications.
158      * @param interrupting If notification should make sounds and be on top section of the shade.
159      */
postNotifications(int count, String pkg, boolean interrupting)160     default void postNotifications(int count, String pkg, boolean interrupting) {
161         throw new UnsupportedOperationException("Not yet implemented.");
162     }
163 
164     /**
165      * Setup Expectations: None
166      *
167      * <p>Posts notification.
168      *
169      * @param builder Builder for notification to post.
170      */
postNotification(Notification.Builder builder)171     default void postNotification(Notification.Builder builder) {
172         throw new UnsupportedOperationException("Not yet implemented.");
173     }
174 
175     /**
176      * Setup Expectations: None
177      *
178      * <p>Cancel any notifications posted by this helper.
179      */
cancelNotifications()180     default void cancelNotifications() {
181         throw new UnsupportedOperationException("Not yet implemented.");
182     }
183 
184     /**
185      * Setup Expectations: Notification shade opened.
186      *
187      * <p>Scrolls to the bottom of the notification shade and taps the "clear all" button if
188      * present.
189      */
clearAllNotifications()190     default void clearAllNotifications() {
191         throw new UnsupportedOperationException("Not yet implemented.");
192     }
193 
194     /**
195      * Setup Expectations: Notification snoozing is enabled.
196      *
197      * <p>Empty the notification shade by first cancelling all of the test app's notifications, then
198      * snoozing all other notifications temporarily. Fails if any notifications are left in the
199      * shade.
200      *
201      * <p>Because unsnoozing can fail from command line, snoozing is implemented with a fixed time,
202      * so tests will take at least as long as the time limit given, plus some buffer built into this
203      * utility, to ensure that this test's snoozing will not interfere with other tests.
204      */
runWithEmptyNotificationShade(Runnable task, long taskTimeLimit)205     default void runWithEmptyNotificationShade(Runnable task, long taskTimeLimit) {
206         throw new UnsupportedOperationException("Not yet implemented.");
207     }
208 
209     /**
210      * Setup expectations: Notification shade opened.
211      *
212      * <p>Opens the first notification by the specified title and checks if the expected application
213      * is in foreground or not
214      *
215      * @param title The title of the notification to open.
216      * @param expectedPkg The foreground application after opening a notification. Won't check the
217      *     foreground application if the application is null
218      */
openNotificationByTitle(String title, String expectedPkg)219     default void openNotificationByTitle(String title, String expectedPkg) {
220         throw new UnsupportedOperationException("Not yet implemented.");
221     }
222 
223     /**
224      * Setup expectations: Notification shade opened.
225      *
226      * <p>Taps the chevron or swipes down on the specified notification and checks if the expanded
227      * view contains the expected text.
228      *
229      * @param notification Notification that should be expanded.
230      * @param dragging By swiping down when {@code true}, by tapping the chevron otherwise.
231      */
expandNotification(UiObject2 notification, boolean dragging)232     default void expandNotification(UiObject2 notification, boolean dragging) {
233         throw new UnsupportedOperationException("Not yet implemented.");
234     }
235 
236     /**
237      * Sets expected app name for notifications.
238      *
239      * @param appName Package name.
240      */
setAppName(String appName)241     default void setAppName(String appName) {
242         throw new UnsupportedOperationException("Not yet implemented.");
243     }
244 
245     /**
246      * Long press on notification to show its hidden menu (a.k.a. guts)
247      *
248      * @param notification Notification.
249      */
showGuts(UiObject2 notification)250     default void showGuts(UiObject2 notification) {
251         throw new UnsupportedOperationException("Not yet implemented.");
252     }
253 
254     /**
255      * Taps the "Done" button on the notification guts.
256      *
257      * @param notification Notification.
258      */
hideGuts(UiObject2 notification)259     default void hideGuts(UiObject2 notification) {
260         throw new UnsupportedOperationException("Not yet implemented.");
261     }
262 
263     /**
264      * Setup expectations: Notification shade opened.
265      *
266      * <p>Find the screenshot notification; expand the notification if it's collapsed and click on
267      * the "share" button.
268      */
shareScreenshotFromNotification(BySelector pageSelector)269     default void shareScreenshotFromNotification(BySelector pageSelector) {
270         throw new UnsupportedOperationException("Not yet implemented.");
271     }
272 
273     /**
274      * Setup expectation: On the expanding notification screen.
275      *
276      * <p>Get the UiObject2 of expanding notification screen.
277      */
getNotificationShadeScrollContainer()278     default UiObject2 getNotificationShadeScrollContainer() {
279         throw new UnsupportedOperationException("Not yet implemented.");
280     }
281 
282     /**
283      * Setup expectation: On the expanding notification screen.
284      *
285      * <p>Get the UiObject2 of Quick Settings container. Quick settings container works both in
286      * expanded and collapsed state, that is contains both QuickQuickSettings and QuickSettings
287      */
getQuickSettingsContainer()288     default UiObject2 getQuickSettingsContainer() {
289         throw new UnsupportedOperationException("Not yet implemented.");
290     }
291 
292     /**
293      * Scroll feeds on Notifications screen
294      *
295      * <p>Setup expectations: Notification is open with lots of notifications.
296      *
297      * @param container The container with scrollable elements.
298      * @param dir The direction of the fling, must be UP or DOWN.
299      */
flingFeed(UiObject2 container, Direction dir)300     default void flingFeed(UiObject2 container, Direction dir) {
301         throw new UnsupportedOperationException("Not yet implemented.");
302     }
303 
304     /**
305      * Scroll feeds on Notifications screen and implement it via "fling" API.
306      *
307      * <p>Setup expectations: Notification is open with lots of notifications.
308      *
309      * @param container The container with scrollable elements.
310      * @param dir The direction of the scroll, must be UP or DOWN.
311      * @param speed The speed of fling.
312      */
flingFeed(UiObject2 container, Direction dir, int speed)313     default void flingFeed(UiObject2 container, Direction dir, int speed) {
314         throw new UnsupportedOperationException("Not yet implemented.");
315     }
316 
317     /**
318      * Setup expectation: on the launcher home screen.
319      *
320      * <p>Open the notification shade by swiping on the home screen.
321      */
swipeToOpen()322     default void swipeToOpen() {
323         throw new UnsupportedOperationException("Not yet implemented.");
324     }
325 
326     /**
327      * Scroll feeds on Notifications screen and implement it by "swipe" API to control the distance.
328      *
329      * <p>Setup expectations: Notification drawer is open with lots of notifications.
330      *
331      * @param container the container with scrollable elements.
332      * @param dir the direction to scroll, must be UP or DOWN.
333      * @param percent The distance to scroll as a percentage of the page's visible size.
334      */
scrollFeed(UiObject2 container, Direction dir, float percent)335     default void scrollFeed(UiObject2 container, Direction dir, float percent) {
336         throw new UnsupportedOperationException("Not yet implemented.");
337     }
338 }
339