17
17
import android .app .Activity ;
18
18
import androidx .annotation .NonNull ;
19
19
import androidx .annotation .Nullable ;
20
+ import com .google .android .gms .tasks .OnCanceledListener ;
21
+ import com .google .android .gms .tasks .OnCompleteListener ;
20
22
import com .google .android .gms .tasks .OnFailureListener ;
21
23
import com .google .android .gms .tasks .OnSuccessListener ;
22
24
import com .google .android .gms .tasks .Task ;
23
25
import com .google .android .gms .tasks .Tasks ;
26
+ import com .google .firebase .appdistribution .FirebaseAppDistributionException .Status ;
24
27
import java .util .concurrent .Executor ;
25
28
29
+ /** Stubbed version of the Firebase App Distribution API */
26
30
public class FirebaseAppDistribution {
27
31
32
+ FirebaseAppDistribution () {}
33
+
28
34
/** @return a FirebaseAppDistribution instance */
29
35
@ NonNull
30
36
public static FirebaseAppDistribution getInstance () {
31
37
return new FirebaseAppDistribution ();
32
38
}
33
39
34
40
/**
35
- * Updates the app to the newest release, if one is available. Returns the release information or
36
- * null if no update is found. Performs the following actions: 1. If tester is not signed in,
37
- * presents the tester with a Google sign in UI 2. Checks if a newer release is available. If so,
38
- * presents the tester with a confirmation dialog to begin the download. 3. For APKs, downloads
39
- * the binary and starts an installation intent. 4. For AABs, directs the tester to the Play app
40
- * to complete the download and installation.
41
+ * Stubbed version of {@code updateIfNewReleaseAvailable()}.
42
+ *
43
+ * @return an {@link UpdateTask} that will fail with a {@link FirebaseAppDistributionException}
44
+ * with status {@link Status#APP_RUNNING_IN_PRODUCTION}.
41
45
*/
42
46
@ NonNull
43
47
public UpdateTask updateIfNewReleaseAvailable () {
44
- return new CompletedUpdateTask ();
48
+ return new AppInProductionUpdateTask ();
45
49
}
46
50
47
- /** Signs in the App Distribution tester. Presents the tester with a Google sign in UI */
51
+ /**
52
+ * Stubbed version of {@code signInTester()}.
53
+ *
54
+ * @return a {@link Task} that will fail with a {@link FirebaseAppDistributionException} with
55
+ * status {@link Status#APP_RUNNING_IN_PRODUCTION}.
56
+ */
48
57
@ NonNull
49
58
public Task <Void > signInTester () {
50
- return Tasks . forResult ( null );
59
+ return getAppInProductionTask ( );
51
60
}
52
61
53
62
/**
54
- * Returns an AppDistributionRelease if one is available for the current signed in tester. If no
55
- * update is found, returns null. If tester is not signed in, presents the tester with a Google
56
- * sign in UI
63
+ * Stubbed version of {@code checkForNewRelease()}.
64
+ *
65
+ * @return a {@link Task} that will fail with a {@link FirebaseAppDistributionException} with
66
+ * status {@link Status#APP_RUNNING_IN_PRODUCTION}.
57
67
*/
58
68
@ NonNull
59
69
public synchronized Task <AppDistributionRelease > checkForNewRelease () {
60
- return Tasks . forResult ( null );
70
+ return getAppInProductionTask ( );
61
71
}
62
72
63
73
/**
64
- * Updates app to the newest release. If the newest release is an APK, downloads the binary and
65
- * starts an installation If the newest release is an AAB, directs the tester to the Play app to
66
- * complete the download and installation.
74
+ * Stubbed version of {@code updateApp()}.
67
75
*
68
- * <p>cancels task with FirebaseAppDistributionException with UPDATE_NOT_AVAILABLE exception if no
69
- * new release is cached from checkForNewRelease
76
+ * @return an {@link UpdateTask} that will fail with a {@link FirebaseAppDistributionException}
77
+ * with status {@link Status#APP_RUNNING_IN_PRODUCTION}.
70
78
*/
71
79
@ NonNull
72
80
public UpdateTask updateApp () {
73
- return new CompletedUpdateTask ();
81
+ return new AppInProductionUpdateTask ();
74
82
}
75
83
76
- /** Returns true if the App Distribution tester is signed in */
84
+ /**
85
+ * Stubbed version of {@code isTesterSignedIn()}.
86
+ *
87
+ * @return false
88
+ */
77
89
public boolean isTesterSignedIn () {
78
90
return false ;
79
91
}
80
92
81
- /** Signs out the App Distribution tester */
93
+ /** Stubbed version of {@code signOutTester()}. */
82
94
public void signOutTester () {}
83
95
84
- private static class CompletedUpdateTask extends UpdateTask {
96
+ private static <TResult > Task <TResult > getAppInProductionTask () {
97
+ return Tasks .forException (
98
+ new FirebaseAppDistributionException (
99
+ "App is running in production. App Distribution is disabled." ,
100
+ Status .APP_RUNNING_IN_PRODUCTION ));
101
+ }
102
+
103
+ private static class AppInProductionUpdateTask extends UpdateTask {
104
+ private final Task <Void > task = getAppInProductionTask ();
105
+
85
106
@ NonNull
86
107
@ Override
87
108
public UpdateTask addOnProgressListener (@ NonNull OnProgressListener listener ) {
@@ -97,76 +118,122 @@ public UpdateTask addOnProgressListener(
97
118
98
119
@ Override
99
120
public boolean isComplete () {
100
- return true ;
121
+ return task . isComplete () ;
101
122
}
102
123
103
124
@ Override
104
125
public boolean isSuccessful () {
105
- return true ;
126
+ return task . isSuccessful () ;
106
127
}
107
128
108
129
@ Override
109
130
public boolean isCanceled () {
110
- return false ;
131
+ return task . isCanceled () ;
111
132
}
112
133
113
134
@ Nullable
114
135
@ Override
115
136
public Void getResult () {
116
- return null ;
137
+ return task . getResult () ;
117
138
}
118
139
119
140
@ Nullable
120
141
@ Override
121
142
public <X extends Throwable > Void getResult (@ NonNull Class <X > aClass ) throws X {
122
- return null ;
143
+ return task . getResult ( aClass ) ;
123
144
}
124
145
125
146
@ Nullable
126
147
@ Override
127
148
public Exception getException () {
128
- return null ;
149
+ return task . getException () ;
129
150
}
130
151
131
152
@ NonNull
132
153
@ Override
133
154
public Task <Void > addOnSuccessListener (
134
155
@ NonNull OnSuccessListener <? super Void > onSuccessListener ) {
156
+ task .addOnSuccessListener (onSuccessListener );
135
157
return this ;
136
158
}
137
159
138
160
@ NonNull
139
161
@ Override
140
162
public Task <Void > addOnSuccessListener (
141
163
@ NonNull Executor executor , @ NonNull OnSuccessListener <? super Void > onSuccessListener ) {
164
+ task .addOnSuccessListener (executor , onSuccessListener );
142
165
return this ;
143
166
}
144
167
145
168
@ NonNull
146
169
@ Override
147
170
public Task <Void > addOnSuccessListener (
148
171
@ NonNull Activity activity , @ NonNull OnSuccessListener <? super Void > onSuccessListener ) {
172
+ task .addOnSuccessListener (activity , onSuccessListener );
149
173
return this ;
150
174
}
151
175
152
176
@ NonNull
153
177
@ Override
154
178
public Task <Void > addOnFailureListener (@ NonNull OnFailureListener onFailureListener ) {
179
+ task .addOnFailureListener (onFailureListener );
155
180
return this ;
156
181
}
157
182
158
183
@ NonNull
159
184
@ Override
160
185
public Task <Void > addOnFailureListener (
161
186
@ NonNull Executor executor , @ NonNull OnFailureListener onFailureListener ) {
187
+ task .addOnFailureListener (executor , onFailureListener );
162
188
return this ;
163
189
}
164
190
165
191
@ NonNull
166
192
@ Override
167
193
public Task <Void > addOnFailureListener (
168
194
@ NonNull Activity activity , @ NonNull OnFailureListener onFailureListener ) {
195
+ task .addOnFailureListener (activity , onFailureListener );
169
196
return this ;
170
197
}
198
+
199
+ @ NonNull
200
+ @ Override
201
+ public Task <Void > addOnCompleteListener (@ NonNull OnCompleteListener <Void > onCompleteListener ) {
202
+ return task .addOnCompleteListener (onCompleteListener );
203
+ }
204
+
205
+ @ NonNull
206
+ @ Override
207
+ public Task <Void > addOnCompleteListener (
208
+ @ NonNull Executor executor , @ NonNull OnCompleteListener <Void > onCompleteListener ) {
209
+ return task .addOnCompleteListener (executor , onCompleteListener );
210
+ }
211
+
212
+ @ NonNull
213
+ @ Override
214
+ public Task <Void > addOnCompleteListener (
215
+ @ NonNull Activity activity , @ NonNull OnCompleteListener <Void > onCompleteListener ) {
216
+ return task .addOnCompleteListener (activity , onCompleteListener );
217
+ }
218
+
219
+ @ NonNull
220
+ @ Override
221
+ public Task <Void > addOnCanceledListener (@ NonNull OnCanceledListener onCanceledListener ) {
222
+ return task .addOnCanceledListener (onCanceledListener );
223
+ }
224
+
225
+ @ NonNull
226
+ @ Override
227
+ public Task <Void > addOnCanceledListener (
228
+ @ NonNull Executor executor , @ NonNull OnCanceledListener onCanceledListener ) {
229
+ return task .addOnCanceledListener (executor , onCanceledListener );
230
+ }
231
+
232
+ @ NonNull
233
+ @ Override
234
+ public Task <Void > addOnCanceledListener (
235
+ @ NonNull Activity activity , @ NonNull OnCanceledListener onCanceledListener ) {
236
+ return task .addOnCanceledListener (activity , onCanceledListener );
237
+ }
171
238
}
172
239
}
0 commit comments