Skip to content

Commit a54d4ca

Browse files
authored
Merge db4cb23 into d939e63
2 parents d939e63 + db4cb23 commit a54d4ca

File tree

6 files changed

+123
-31
lines changed

6 files changed

+123
-31
lines changed

firebase-appdistribution/firebase-appdistribution.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ dependencies {
5454
testImplementation "org.robolectric:robolectric:$robolectricVersion"
5555
testImplementation "com.google.truth:truth:$googleTruthVersion"
5656
testImplementation 'org.mockito:mockito-inline:3.4.0'
57-
androidTestImplementation "org.mockito:mockito-android:3.4.0"
5857
testImplementation 'androidx.test:core:1.2.0'
5958

6059
implementation 'com.google.android.gms:play-services-tasks:18.0.1'
@@ -64,4 +63,13 @@ dependencies {
6463
implementation 'androidx.appcompat:appcompat:1.3.0'
6564
implementation "androidx.browser:browser:1.3.0"
6665
implementation "androidx.constraintlayout:constraintlayout:2.1.4"
66+
67+
androidTestImplementation project(':integ-testing')
68+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
69+
androidTestImplementation 'androidx.test:runner:1.2.0'
70+
androidTestImplementation "com.google.truth:truth:$googleTruthVersion"
71+
androidTestImplementation 'junit:junit:4.12'
72+
androidTestImplementation "androidx.annotation:annotation:1.0.0"
73+
androidTestImplementation 'org.mockito:mockito-core:2.25.0'
74+
androidTestImplementation 'org.mockito:mockito-inline:2.25.0'
6775
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2022 Google LLC -->
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+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
17+
package="com.google.firebase.installations">
18+
19+
<application>
20+
<uses-library android:name="android.test.runner"/>
21+
</application>
22+
23+
<instrumentation
24+
android:name="androidx.test.runner.AndroidJUnitRunner"
25+
android:targetPackage="com.google.firebase.appdistribution" />
26+
</manifest>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2022 Google LLC
2+
//
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+
package com.google.firebase.appdistribution;
15+
16+
import androidx.test.core.app.ApplicationProvider;
17+
import androidx.test.ext.junit.runners.AndroidJUnit4;
18+
import com.google.firebase.FirebaseApp;
19+
import com.google.firebase.FirebaseOptions;
20+
import com.google.firebase.appdistribution.internal.FirebaseAppDistributionProxy;
21+
import com.google.firebase.testing.integ.StrictModeRule;
22+
import org.junit.Rule;
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
26+
@RunWith(AndroidJUnit4.class)
27+
public class StrictModeTest {
28+
29+
@Rule public StrictModeRule strictMode = new StrictModeRule();
30+
31+
@Test
32+
public void initializingFirebaseAppdistribution_shouldNotViolateStrictMode() {
33+
strictMode.runOnMainThread(
34+
() -> {
35+
FirebaseApp app =
36+
FirebaseApp.initializeApp(
37+
ApplicationProvider.getApplicationContext(),
38+
new FirebaseOptions.Builder()
39+
.setApiKey("api")
40+
.setProjectId("123")
41+
.setApplicationId("appId")
42+
.build(),
43+
"hello");
44+
app.get(FirebaseAppDistribution.class);
45+
app.get(FirebaseAppDistributionProxy.class);
46+
});
47+
}
48+
}

firebase-appdistribution/src/main/java/com/google/firebase/appdistribution/impl/SignInStorage.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,29 @@
1616

1717
import android.content.Context;
1818
import android.content.SharedPreferences;
19+
import com.google.firebase.components.Lazy;
1920

2021
/** Class that handles storage for App Distribution SignIn persistence. */
2122
class SignInStorage {
2223

2324
private static final String SIGNIN_PREFERENCES_NAME = "FirebaseAppDistributionSignInStorage";
2425
private static final String SIGNIN_TAG = "firebase_app_distribution_signin";
2526

26-
private final SharedPreferences signInSharedPreferences;
27+
private final Lazy<SharedPreferences> signInSharedPreferences;
2728

2829
SignInStorage(Context applicationContext) {
2930
this.signInSharedPreferences =
30-
applicationContext.getSharedPreferences(SIGNIN_PREFERENCES_NAME, Context.MODE_PRIVATE);
31+
new Lazy(
32+
() ->
33+
applicationContext.getSharedPreferences(
34+
SIGNIN_PREFERENCES_NAME, Context.MODE_PRIVATE));
3135
}
3236

3337
void setSignInStatus(boolean testerSignedIn) {
34-
this.signInSharedPreferences.edit().putBoolean(SIGNIN_TAG, testerSignedIn).apply();
38+
this.signInSharedPreferences.get().edit().putBoolean(SIGNIN_TAG, testerSignedIn).apply();
3539
}
3640

3741
boolean getSignInStatus() {
38-
return signInSharedPreferences.getBoolean(SIGNIN_TAG, false);
42+
return signInSharedPreferences.get().getBoolean(SIGNIN_TAG, false);
3943
}
4044
}

firebase-appdistribution/test-app/src/main/java/com/googletest/firebase/appdistribution/testapp/MainActivity.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ import androidx.appcompat.app.AppCompatActivity
1212
import androidx.appcompat.widget.AppCompatButton
1313
import com.google.android.gms.tasks.Task
1414
import com.google.firebase.appdistribution.AppDistributionRelease
15-
import com.google.firebase.appdistribution.FirebaseAppDistribution
1615
import com.google.firebase.appdistribution.UpdateProgress
16+
import com.google.firebase.appdistribution.ktx.appDistribution
17+
import com.google.firebase.ktx.Firebase
1718
import java.util.concurrent.ExecutorService
1819
import java.util.concurrent.Executors
1920

2021
class MainActivity : AppCompatActivity() {
21-
var firebaseAppDistribution: FirebaseAppDistribution = FirebaseAppDistribution.getInstance()
22+
var firebaseAppDistribution = Firebase.appDistribution
2223
var updateTask: Task<Void>? = null
23-
var release: AppDistributionRelease? = null
2424
val executorService: ExecutorService = Executors.newFixedThreadPool(1)
25+
2526
lateinit var signInButton: AppCompatButton
2627
lateinit var signOutButton: AppCompatButton
2728
lateinit var checkForUpdateButton: AppCompatButton
@@ -110,10 +111,11 @@ class MainActivity : AppCompatActivity() {
110111
firebaseAppDistribution
111112
.checkForNewRelease()
112113
.addOnSuccessListener {
113-
setupUI(
114-
isSignedIn = firebaseAppDistribution.isTesterSignedIn,
115-
isUpdateAvailable = it != null,
116-
release = it)
114+
release ->
115+
setupUI(
116+
isSignedIn = firebaseAppDistribution.isTesterSignedIn,
117+
isUpdateAvailable = release != null,
118+
release = release)
117119
}
118120
.addOnFailureListener { failureListener(it) }
119121
}
@@ -123,11 +125,11 @@ class MainActivity : AppCompatActivity() {
123125
firebaseAppDistribution
124126
.checkForNewRelease()
125127
.addOnSuccessListener {
126-
release = it
127-
setupUI(
128-
isSignedIn = firebaseAppDistribution.isTesterSignedIn,
129-
isUpdateAvailable = release != null,
130-
release = release)
128+
release ->
129+
setupUI(
130+
isSignedIn = firebaseAppDistribution.isTesterSignedIn,
131+
isUpdateAvailable = release != null,
132+
release = release)
131133
}
132134
.addOnFailureListener { failureListener(it) }
133135
}

firebase-appdistribution/test-app/test-app.gradle

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,26 @@ plugins {
1818
}
1919

2020
android {
21-
compileSdkVersion 30
21+
compileSdk 33
2222

2323
defaultConfig {
2424
applicationId "com.googletest.firebase.appdistribution.testapp"
2525
minSdkVersion 19
26-
targetSdkVersion 30
26+
targetSdkVersion 33
2727
versionName "1.0"
2828
versionCode 1
2929

3030
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3131
}
3232

3333
buildTypes {
34-
// This is so we can build the "release" variant for the "dev-app" (and the SDK) without
34+
// This is so we can build the "release" variant for the "test-app" (and the SDK) without
3535
// needing to have the app signed.
3636
release {
3737
initWith debug
3838
}
3939
}
40+
4041
compileOptions {
4142
sourceCompatibility JavaVersion.VERSION_1_8
4243
targetCompatibility JavaVersion.VERSION_1_8
@@ -50,21 +51,24 @@ dependencies {
5051
// TODO(rachelprince): Add flag to build with public version of SDK
5152
println("Building with HEAD version ':firebase-appdistribution' of SDK")
5253

53-
// Debug variant uses full SDK
54-
debugImplementation project(':firebase-appdistribution-api') // TODO(lkellogg): why doesn't this get picked up transitively?
55-
debugImplementation project(':firebase-appdistribution')
54+
// All variants use the API
55+
implementation project(':firebase-appdistribution-api:ktx')
5656

57-
// Release variant just uses the API, as if publishing to Play
58-
releaseImplementation project(':firebase-appdistribution-api')
57+
// In this test project we also need to explicitly declare these dependencies
58+
implementation project(':firebase-appdistribution-api')
59+
implementation project(':firebase-common:ktx')
60+
implementation "com.google.android.gms:play-services-tasks:18.0.2"
5961

60-
implementation "com.google.android.gms:play-services-tasks:18.0.1"
62+
// Debug uses the full implementation
63+
debugImplementation project(':firebase-appdistribution')
6164

65+
// Other dependencies
6266
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
63-
implementation 'androidx.core:core-ktx:1.5.0'
64-
implementation "androidx.core:core:1.6.0"
65-
implementation 'androidx.appcompat:appcompat:1.3.0'
66-
implementation 'com.google.android.material:material:1.2.1'
67-
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
67+
implementation 'androidx.core:core-ktx:1.9.0'
68+
implementation "androidx.core:core:1.9.0"
69+
implementation 'androidx.appcompat:appcompat:1.5.1'
70+
implementation 'com.google.android.material:material:1.6.1'
71+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
6872
testImplementation 'junit:junit:4.+'
6973
}
7074

0 commit comments

Comments
 (0)