Skip to content

Commit fc51d6f

Browse files
authored
Fail tasks returned from firebase-app-distribution-stub (#3295)
* Fail tasks returned from firebase-app-distribution-stub * Fix package names * Update firebase-app-distribution-stub api.txt * Fix ktx package directory structure
1 parent 22ee484 commit fc51d6f

File tree

12 files changed

+231
-53
lines changed

12 files changed

+231
-53
lines changed

firebase-app-distribution-stub/api.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ package com.google.firebase.appdistribution {
1515
}
1616

1717
public class FirebaseAppDistribution {
18-
ctor public FirebaseAppDistribution();
1918
method @NonNull public com.google.android.gms.tasks.Task<com.google.firebase.appdistribution.AppDistributionRelease> checkForNewRelease();
2019
method @NonNull public static com.google.firebase.appdistribution.FirebaseAppDistribution getInstance();
2120
method public boolean isTesterSignedIn();
@@ -26,7 +25,6 @@ package com.google.firebase.appdistribution {
2625
}
2726

2827
public class FirebaseAppDistributionException extends com.google.firebase.FirebaseException {
29-
ctor public FirebaseAppDistributionException();
3028
method @NonNull public com.google.firebase.appdistribution.FirebaseAppDistributionException.Status getErrorCode();
3129
method @Nullable public com.google.firebase.appdistribution.AppDistributionRelease getRelease();
3230
}

firebase-app-distribution-stub/firebase-app-distribution-stub.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ dependencies {
4545

4646
testImplementation 'junit:junit:4.13.2'
4747
testImplementation "com.google.truth:truth:$googleTruthVersion"
48+
testImplementation "org.robolectric:robolectric:$robolectricVersion"
4849

4950
compileOnly 'com.google.auto.value:auto-value-annotations:1.6.5'
5051
annotationProcessor 'com.google.auto.value:auto-value:1.6.5'

firebase-app-distribution-stub/ktx/api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Signature format: 2.0
2-
package com.google.firebase.app.distribution.ktx {
2+
package com.google.firebase.appdistribution.ktx {
33

44
public final class FirebaseAppDistributionKt {
55
ctor public FirebaseAppDistributionKt();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.google.firebase.app.distribution.ktx">
2+
package="com.google.firebase.appdistribution.ktx">
33
<!--Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds-->
44
<!--<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />-->
55
<uses-permission android:name="android.permission.INTERNET"/>
@@ -9,5 +9,5 @@
99

1010
<instrumentation
1111
android:name="androidx.test.runner.AndroidJUnitRunner"
12-
android:targetPackage="3com.google.firebase.app.distribution.ktx" />
12+
android:targetPackage="3com.google.firebase.appdistribution.ktx" />
1313
</manifest>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.firebase.app.distribution.ktx
15+
package com.google.firebase.appdistribution.ktx
1616

1717
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
1818
import com.google.common.truth.Truth

firebase-app-distribution-stub/ktx/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<!-- limitations under the License. -->
1414

1515
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
16-
package="com.google.firebase.app.distribution.ktx">
16+
package="com.google.firebase.appdistribution.ktx">
1717
<uses-sdk android:minSdkVersion="16"/>
1818

1919
<application>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package com.google.firebase.app.distribution.ktx
15+
package com.google.firebase.appdistribution.ktx
1616

1717
import com.google.firebase.appdistribution.FirebaseAppDistribution
1818
import com.google.firebase.ktx.Firebase

firebase-app-distribution-stub/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<!-- limitations under the License. -->
1515

1616
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
17-
package="com.google.firebase.app.distribution">
17+
package="com.google.firebase.appdistribution">
1818

1919
<application>
2020
</application>

firebase-app-distribution-stub/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistribution.java

Lines changed: 95 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,71 +17,92 @@
1717
import android.app.Activity;
1818
import androidx.annotation.NonNull;
1919
import androidx.annotation.Nullable;
20+
import com.google.android.gms.tasks.OnCanceledListener;
21+
import com.google.android.gms.tasks.OnCompleteListener;
2022
import com.google.android.gms.tasks.OnFailureListener;
2123
import com.google.android.gms.tasks.OnSuccessListener;
2224
import com.google.android.gms.tasks.Task;
2325
import com.google.android.gms.tasks.Tasks;
26+
import com.google.firebase.appdistribution.FirebaseAppDistributionException.Status;
2427
import java.util.concurrent.Executor;
2528

29+
/** Stubbed version of the Firebase App Distribution API */
2630
public class FirebaseAppDistribution {
2731

32+
FirebaseAppDistribution() {}
33+
2834
/** @return a FirebaseAppDistribution instance */
2935
@NonNull
3036
public static FirebaseAppDistribution getInstance() {
3137
return new FirebaseAppDistribution();
3238
}
3339

3440
/**
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}.
4145
*/
4246
@NonNull
4347
public UpdateTask updateIfNewReleaseAvailable() {
44-
return new CompletedUpdateTask();
48+
return new AppInProductionUpdateTask();
4549
}
4650

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+
*/
4857
@NonNull
4958
public Task<Void> signInTester() {
50-
return Tasks.forResult(null);
59+
return getAppInProductionTask();
5160
}
5261

5362
/**
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}.
5767
*/
5868
@NonNull
5969
public synchronized Task<AppDistributionRelease> checkForNewRelease() {
60-
return Tasks.forResult(null);
70+
return getAppInProductionTask();
6171
}
6272

6373
/**
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()}.
6775
*
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}.
7078
*/
7179
@NonNull
7280
public UpdateTask updateApp() {
73-
return new CompletedUpdateTask();
81+
return new AppInProductionUpdateTask();
7482
}
7583

76-
/** Returns true if the App Distribution tester is signed in */
84+
/**
85+
* Stubbed version of {@code isTesterSignedIn()}.
86+
*
87+
* @return false
88+
*/
7789
public boolean isTesterSignedIn() {
7890
return false;
7991
}
8092

81-
/** Signs out the App Distribution tester */
93+
/** Stubbed version of {@code signOutTester()}. */
8294
public void signOutTester() {}
8395

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+
85106
@NonNull
86107
@Override
87108
public UpdateTask addOnProgressListener(@NonNull OnProgressListener listener) {
@@ -97,76 +118,122 @@ public UpdateTask addOnProgressListener(
97118

98119
@Override
99120
public boolean isComplete() {
100-
return true;
121+
return task.isComplete();
101122
}
102123

103124
@Override
104125
public boolean isSuccessful() {
105-
return true;
126+
return task.isSuccessful();
106127
}
107128

108129
@Override
109130
public boolean isCanceled() {
110-
return false;
131+
return task.isCanceled();
111132
}
112133

113134
@Nullable
114135
@Override
115136
public Void getResult() {
116-
return null;
137+
return task.getResult();
117138
}
118139

119140
@Nullable
120141
@Override
121142
public <X extends Throwable> Void getResult(@NonNull Class<X> aClass) throws X {
122-
return null;
143+
return task.getResult(aClass);
123144
}
124145

125146
@Nullable
126147
@Override
127148
public Exception getException() {
128-
return null;
149+
return task.getException();
129150
}
130151

131152
@NonNull
132153
@Override
133154
public Task<Void> addOnSuccessListener(
134155
@NonNull OnSuccessListener<? super Void> onSuccessListener) {
156+
task.addOnSuccessListener(onSuccessListener);
135157
return this;
136158
}
137159

138160
@NonNull
139161
@Override
140162
public Task<Void> addOnSuccessListener(
141163
@NonNull Executor executor, @NonNull OnSuccessListener<? super Void> onSuccessListener) {
164+
task.addOnSuccessListener(executor, onSuccessListener);
142165
return this;
143166
}
144167

145168
@NonNull
146169
@Override
147170
public Task<Void> addOnSuccessListener(
148171
@NonNull Activity activity, @NonNull OnSuccessListener<? super Void> onSuccessListener) {
172+
task.addOnSuccessListener(activity, onSuccessListener);
149173
return this;
150174
}
151175

152176
@NonNull
153177
@Override
154178
public Task<Void> addOnFailureListener(@NonNull OnFailureListener onFailureListener) {
179+
task.addOnFailureListener(onFailureListener);
155180
return this;
156181
}
157182

158183
@NonNull
159184
@Override
160185
public Task<Void> addOnFailureListener(
161186
@NonNull Executor executor, @NonNull OnFailureListener onFailureListener) {
187+
task.addOnFailureListener(executor, onFailureListener);
162188
return this;
163189
}
164190

165191
@NonNull
166192
@Override
167193
public Task<Void> addOnFailureListener(
168194
@NonNull Activity activity, @NonNull OnFailureListener onFailureListener) {
195+
task.addOnFailureListener(activity, onFailureListener);
169196
return this;
170197
}
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+
}
171238
}
172239
}

firebase-app-distribution-stub/src/main/java/com/google/firebase/appdistribution/FirebaseAppDistributionException.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,23 @@ public enum Status {
5959
RELEASE_URL_EXPIRED,
6060
}
6161

62+
@NonNull private final Status status;
63+
@Nullable private final AppDistributionRelease release;
64+
65+
FirebaseAppDistributionException(@NonNull String message, @NonNull Status status) {
66+
super(message);
67+
this.status = status;
68+
this.release = null;
69+
}
70+
6271
/** Get cached release when error was thrown */
6372
@Nullable
6473
public AppDistributionRelease getRelease() {
65-
return null;
74+
return release;
6675
}
6776

6877
@NonNull
6978
public Status getErrorCode() {
70-
return Status.UNKNOWN;
79+
return status;
7180
}
7281
}

0 commit comments

Comments
 (0)