1 /*
2  * Copyright (C) 2021 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 package com.android.eventlib.events.activities
17 
18 import android.content.ComponentName
19 import com.android.bedstead.nene.TestApis
20 import com.android.bedstead.nene.activities.Activity
21 import com.android.bedstead.nene.activities.NeneActivity
22 import com.android.bedstead.nene.users.UserReference
23 import com.android.eventlib.events.activities.ActivityCreatedEvent.ActivityCreatedEventQuery
24 import com.android.eventlib.events.activities.ActivityDestroyedEvent.ActivityDestroyedEventQuery
25 import com.android.eventlib.events.activities.ActivityPausedEvent.ActivityPausedEventQuery
26 import com.android.eventlib.events.activities.ActivityRestartedEvent.ActivityRestartedEventQuery
27 import com.android.eventlib.events.activities.ActivityResumedEvent.ActivityResumedEventQuery
28 import com.android.eventlib.events.activities.ActivityStartedEvent.ActivityStartedEventQuery
29 import com.android.eventlib.events.activities.ActivityStoppedEvent.ActivityStoppedEventQuery
30 
31 /**
32  * Quick access to event queries about activities.
33  */
34 interface ActivityEvents {
35     /**
36      * Query for when an activity is created.
37      *
38      *
39      * Additional filters can be added to the returned object.
40      *
41      *
42      * `#poll` can be used to fetch results, and the result can be asserted on.
43      */
activityCreatednull44     fun activityCreated(): ActivityCreatedEventQuery
45 
46     /**
47      * Query for when an activity is destroyed.
48      *
49      *
50      * Additional filters can be added to the returned object.
51      *
52      *
53      * `#poll` can be used to fetch results, and the result can be asserted on.
54      */
55     fun activityDestroyed(): ActivityDestroyedEventQuery
56 
57     /**
58      * Query for when an activity is paused.
59      *
60      *
61      * Additional filters can be added to the returned object.
62      *
63      *
64      * `#poll` can be used to fetch results, and the result can be asserted on.
65      */
66     fun activityPaused(): ActivityPausedEventQuery
67 
68     /**
69      * Query for when an activity is restarted.
70      *
71      *
72      * Additional filters can be added to the returned object.
73      *
74      *
75      * `#poll` can be used to fetch results, and the result can be asserted on.
76      */
77     fun activityRestarted(): ActivityRestartedEventQuery
78 
79     /**
80      * Query for when an activity is resumed.
81      *
82      *
83      * Additional filters can be added to the returned object.
84      *
85      *
86      * `#poll` can be used to fetch results, and the result can be asserted on.
87      */
88     fun activityResumed(): ActivityResumedEventQuery
89 
90     /**
91      * Query for when an activity is started.
92      *
93      *
94      * Additional filters can be added to the returned object.
95      *
96      *
97      * `#poll` can be used to fetch results, and the result can be asserted on.
98      */
99     fun activityStarted(): ActivityStartedEventQuery
100 
101     /**
102      * Query for when an activity is stopped.
103      *
104      *
105      * Additional filters can be added to the returned object.
106      *
107      *
108      * `#poll` can be used to fetch results, and the result can be asserted on.
109      */
110     fun activityStopped(): ActivityStoppedEventQuery
111 
112     companion object {
113         /** Access events for activity.  */
114         @JvmStatic
115         fun forActivity(activity: NeneActivity): ActivityEvents =
116             ActivityEventsImpl(activity)
117 
118         /** Access events for activity.  */
119         @JvmStatic
120         fun forActivity(activity: Activity<NeneActivity>): ActivityEvents =
121             ActivityEventsImpl(activity.activity())
122 
123         /** Access events for activity.  */
124         @JvmStatic
125         @JvmOverloads
126         fun forActivity(
127             componentName: ComponentName,
128             user: UserReference = TestApis.users().instrumented()
129         ): ActivityEvents =
130             ActivityEventsImpl(componentName, user.userHandle())
131     }
132 }
133