Skip to content

Commit 95e217e

Browse files
authored
Merge 427a4fa into 66c7398
2 parents 66c7398 + 427a4fa commit 95e217e

File tree

20 files changed

+152
-72
lines changed

20 files changed

+152
-72
lines changed

appcheck/firebase-appcheck-debug-testing/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Unreleased
2+
* [changed] Integrated the [app_check] Debug Testing SDK with Firebase Components. (#4436)
23

34
# 16.1.0
45
* [unchanged] Updated to accommodate the release of the updated

appcheck/firebase-appcheck-debug/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Unreleased
2+
* [changed] Migrated [app_check] SDKs to use standard Firebase executors. (#4431, #4449)
3+
* [changed] Integrated the [app_check] Debug SDK with Firebase Components. (#4436)
24

35
# 16.1.0
46
* [unchanged] Updated to accommodate the release of the updated

appcheck/firebase-appcheck-debug/firebase-appcheck-debug.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ android {
4141
}
4242

4343
dependencies {
44+
implementation project(':firebase-annotations')
4445
implementation project(':firebase-common')
4546
implementation project(':firebase-components')
4647
implementation project(':appcheck:firebase-appcheck')
@@ -49,6 +50,7 @@ dependencies {
4950

5051
javadocClasspath 'com.google.auto.value:auto-value-annotations:1.6.6'
5152

53+
testImplementation project(':integ-testing')
5254
testImplementation 'junit:junit:4.13-beta-2'
5355
testImplementation 'org.mockito:mockito-core:2.25.0'
5456
testImplementation "org.robolectric:robolectric:$robolectricVersion"

appcheck/firebase-appcheck-debug/src/main/java/com/google/firebase/appcheck/debug/FirebaseAppCheckDebugRegistrar.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616

1717
import com.google.android.gms.common.annotation.KeepForSdk;
1818
import com.google.firebase.FirebaseApp;
19+
import com.google.firebase.annotations.concurrent.Background;
20+
import com.google.firebase.annotations.concurrent.Blocking;
1921
import com.google.firebase.appcheck.debug.internal.DebugAppCheckProvider;
2022
import com.google.firebase.components.Component;
2123
import com.google.firebase.components.ComponentRegistrar;
2224
import com.google.firebase.components.Dependency;
25+
import com.google.firebase.components.Qualified;
2326
import com.google.firebase.platforminfo.LibraryVersionComponent;
2427
import java.util.Arrays;
2528
import java.util.List;
29+
import java.util.concurrent.Executor;
2630

2731
/**
2832
* {@link ComponentRegistrar} for setting up FirebaseAppCheck debug's dependency injections in
@@ -36,16 +40,23 @@ public class FirebaseAppCheckDebugRegistrar implements ComponentRegistrar {
3640

3741
@Override
3842
public List<Component<?>> getComponents() {
43+
Qualified<Executor> backgroundExecutor = Qualified.qualified(Background.class, Executor.class);
44+
Qualified<Executor> blockingExecutor = Qualified.qualified(Blocking.class, Executor.class);
45+
3946
return Arrays.asList(
4047
Component.builder(DebugAppCheckProvider.class)
4148
.name(LIBRARY_NAME)
4249
.add(Dependency.required(FirebaseApp.class))
4350
.add(Dependency.optionalProvider(InternalDebugSecretProvider.class))
51+
.add(Dependency.required(backgroundExecutor))
52+
.add(Dependency.required(blockingExecutor))
4453
.factory(
4554
(container) ->
4655
new DebugAppCheckProvider(
4756
container.get(FirebaseApp.class),
48-
container.getProvider(InternalDebugSecretProvider.class)))
57+
container.getProvider(InternalDebugSecretProvider.class),
58+
container.get(backgroundExecutor),
59+
container.get(blockingExecutor)))
4960
.build(),
5061
LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME));
5162
}

appcheck/firebase-appcheck-debug/src/main/java/com/google/firebase/appcheck/debug/internal/DebugAppCheckProvider.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.google.android.gms.tasks.TaskCompletionSource;
2525
import com.google.android.gms.tasks.Tasks;
2626
import com.google.firebase.FirebaseApp;
27+
import com.google.firebase.annotations.concurrent.Background;
28+
import com.google.firebase.annotations.concurrent.Blocking;
2729
import com.google.firebase.appcheck.AppCheckProvider;
2830
import com.google.firebase.appcheck.AppCheckToken;
2931
import com.google.firebase.appcheck.debug.InternalDebugSecretProvider;
@@ -32,27 +34,26 @@
3234
import com.google.firebase.appcheck.internal.RetryManager;
3335
import com.google.firebase.inject.Provider;
3436
import java.util.UUID;
35-
import java.util.concurrent.ExecutorService;
36-
import java.util.concurrent.Executors;
37+
import java.util.concurrent.Executor;
3738

3839
public class DebugAppCheckProvider implements AppCheckProvider {
3940

4041
private static final String TAG = DebugAppCheckProvider.class.getName();
4142
private static final String UTF_8 = "UTF-8";
4243

4344
private final NetworkClient networkClient;
44-
private final ExecutorService backgroundExecutor;
45+
private final Executor blockingExecutor;
4546
private final RetryManager retryManager;
4647
private final Task<String> debugSecretTask;
4748

48-
// TODO(b/258273630): Migrate to go/firebase-android-executors
49-
@SuppressLint("ThreadPoolCreation")
5049
public DebugAppCheckProvider(
5150
@NonNull FirebaseApp firebaseApp,
52-
@NonNull Provider<InternalDebugSecretProvider> debugSecretProvider) {
51+
@NonNull Provider<InternalDebugSecretProvider> debugSecretProvider,
52+
@Background Executor backgroundExecutor,
53+
@Blocking Executor blockingExecutor) {
5354
checkNotNull(firebaseApp);
5455
this.networkClient = new NetworkClient(firebaseApp);
55-
this.backgroundExecutor = Executors.newCachedThreadPool();
56+
this.blockingExecutor = blockingExecutor;
5657
this.retryManager = new RetryManager();
5758

5859
String debugSecret = null;
@@ -61,26 +62,26 @@ public DebugAppCheckProvider(
6162
}
6263
this.debugSecretTask =
6364
debugSecret == null
64-
? determineDebugSecret(firebaseApp, this.backgroundExecutor)
65+
? determineDebugSecret(firebaseApp, backgroundExecutor)
6566
: Tasks.forResult(debugSecret);
6667
}
6768

6869
@VisibleForTesting
6970
DebugAppCheckProvider(
7071
@NonNull String debugSecret,
7172
@NonNull NetworkClient networkClient,
72-
@NonNull ExecutorService backgroundExecutor,
73+
@NonNull Executor blockingExecutor,
7374
@NonNull RetryManager retryManager) {
7475
this.networkClient = networkClient;
75-
this.backgroundExecutor = backgroundExecutor;
76+
this.blockingExecutor = blockingExecutor;
7677
this.retryManager = retryManager;
7778
this.debugSecretTask = Tasks.forResult(debugSecret);
7879
}
7980

8081
@VisibleForTesting
8182
@NonNull
8283
static Task<String> determineDebugSecret(
83-
@NonNull FirebaseApp firebaseApp, @NonNull ExecutorService executor) {
84+
@NonNull FirebaseApp firebaseApp, @NonNull Executor executor) {
8485
TaskCompletionSource<String> taskCompletionSource = new TaskCompletionSource<>();
8586
executor.execute(
8687
() -> {
@@ -111,7 +112,7 @@ public Task<AppCheckToken> getToken() {
111112
task -> {
112113
ExchangeDebugTokenRequest request = new ExchangeDebugTokenRequest(task.getResult());
113114
return Tasks.call(
114-
backgroundExecutor,
115+
blockingExecutor,
115116
() ->
116117
networkClient.exchangeAttestationForAppCheckToken(
117118
request.toJsonString().getBytes(UTF_8),

appcheck/firebase-appcheck-debug/src/test/java/com/google/firebase/appcheck/debug/FirebaseAppCheckDebugRegistrarTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
import static com.google.common.truth.Truth.assertThat;
1818

1919
import com.google.firebase.FirebaseApp;
20+
import com.google.firebase.annotations.concurrent.Background;
21+
import com.google.firebase.annotations.concurrent.Blocking;
2022
import com.google.firebase.components.Component;
2123
import com.google.firebase.components.Dependency;
24+
import com.google.firebase.components.Qualified;
2225
import java.util.List;
26+
import java.util.concurrent.Executor;
2327
import org.junit.Test;
2428
import org.junit.runner.RunWith;
2529
import org.robolectric.RobolectricTestRunner;
@@ -37,7 +41,9 @@ public void testGetComponents() {
3741
assertThat(appCheckDebugComponent.getDependencies())
3842
.containsExactly(
3943
Dependency.required(FirebaseApp.class),
40-
Dependency.optionalProvider(InternalDebugSecretProvider.class));
44+
Dependency.optionalProvider(InternalDebugSecretProvider.class),
45+
Dependency.required(Qualified.qualified(Background.class, Executor.class)),
46+
Dependency.required(Qualified.qualified(Blocking.class, Executor.class)));
4147
assertThat(appCheckDebugComponent.isLazy()).isTrue();
4248
}
4349
}

appcheck/firebase-appcheck-debug/src/test/java/com/google/firebase/appcheck/debug/internal/DebugAppCheckProviderTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333
import com.google.firebase.appcheck.internal.DefaultAppCheckToken;
3434
import com.google.firebase.appcheck.internal.NetworkClient;
3535
import com.google.firebase.appcheck.internal.RetryManager;
36+
import com.google.firebase.concurrent.TestOnlyExecutors;
3637
import java.io.IOException;
37-
import java.util.concurrent.ExecutorService;
38+
import java.util.concurrent.Executor;
3839
import org.junit.After;
3940
import org.junit.Before;
4041
import org.junit.Test;
@@ -72,7 +73,8 @@ public class DebugAppCheckProviderTest {
7273

7374
private StorageHelper storageHelper;
7475
private SharedPreferences sharedPreferences;
75-
private ExecutorService backgroundExecutor = MoreExecutors.newDirectExecutorService();
76+
// TODO(b/258273630): Use TestOnlyExecutors instead of MoreExecutors.directExecutor().
77+
private Executor executor = MoreExecutors.directExecutor();
7678

7779
@Before
7880
public void setup() {
@@ -100,7 +102,8 @@ public void testPublicConstructor_nullFirebaseApp_expectThrows() {
100102
assertThrows(
101103
NullPointerException.class,
102104
() -> {
103-
new DebugAppCheckProvider(null, null);
105+
new DebugAppCheckProvider(
106+
null, null, TestOnlyExecutors.background(), TestOnlyExecutors.blocking());
104107
});
105108
}
106109

@@ -110,7 +113,7 @@ public void testDetermineDebugSecret_noStoredSecret_createsNewSecret() {
110113
assertThat(storageHelper.retrieveDebugSecret()).isNull();
111114

112115
Task<String> debugSecretTask =
113-
DebugAppCheckProvider.determineDebugSecret(mockFirebaseApp, backgroundExecutor);
116+
DebugAppCheckProvider.determineDebugSecret(mockFirebaseApp, executor);
114117
assertThat(storageHelper.retrieveDebugSecret()).isNotNull();
115118
assertThat(storageHelper.retrieveDebugSecret()).isEqualTo(debugSecretTask.getResult());
116119
}
@@ -120,7 +123,7 @@ public void testDetermineDebugSecret_storedSecret_usesExistingSecret() {
120123
storageHelper.saveDebugSecret(DEBUG_SECRET);
121124

122125
Task<String> debugSecretTask =
123-
DebugAppCheckProvider.determineDebugSecret(mockFirebaseApp, backgroundExecutor);
126+
DebugAppCheckProvider.determineDebugSecret(mockFirebaseApp, executor);
124127
assertThat(debugSecretTask.getResult()).isEqualTo(DEBUG_SECRET);
125128
assertThat(storageHelper.retrieveDebugSecret()).isEqualTo(DEBUG_SECRET);
126129
}
@@ -134,8 +137,7 @@ public void exchangeDebugToken_onSuccess_setsTaskResult() throws Exception {
134137
when(mockAppCheckTokenResponse.getTimeToLive()).thenReturn(TIME_TO_LIVE);
135138

136139
DebugAppCheckProvider provider =
137-
new DebugAppCheckProvider(
138-
DEBUG_SECRET, mockNetworkClient, backgroundExecutor, mockRetryManager);
140+
new DebugAppCheckProvider(DEBUG_SECRET, mockNetworkClient, executor, mockRetryManager);
139141
Task<AppCheckToken> task = provider.getToken();
140142

141143
verify(mockNetworkClient)
@@ -153,8 +155,7 @@ public void exchangeDebugToken_onFailure_setsTaskException() throws Exception {
153155
.thenThrow(new IOException());
154156

155157
DebugAppCheckProvider provider =
156-
new DebugAppCheckProvider(
157-
DEBUG_SECRET, mockNetworkClient, backgroundExecutor, mockRetryManager);
158+
new DebugAppCheckProvider(DEBUG_SECRET, mockNetworkClient, executor, mockRetryManager);
158159
Task<AppCheckToken> task = provider.getToken();
159160

160161
verify(mockNetworkClient)

appcheck/firebase-appcheck-playintegrity/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Unreleased
2+
* [changed] Migrated [app_check] SDKs to use standard Firebase executors. (#4431, #4449)
3+
* [changed] Integrated the [app_check] Play Integrity SDK with Firebase Components. (#4436)
24

35
# 16.1.0
46
* [unchanged] Updated to accommodate the release of the updated

appcheck/firebase-appcheck-playintegrity/firebase-appcheck-playintegrity.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ android {
4141
}
4242

4343
dependencies {
44+
implementation project(':firebase-annotations')
4445
implementation project(':firebase-common')
4546
implementation project(':firebase-components')
4647
implementation project(':appcheck:firebase-appcheck')
@@ -50,6 +51,7 @@ dependencies {
5051

5152
javadocClasspath 'com.google.auto.value:auto-value-annotations:1.6.6'
5253

54+
testImplementation project(':integ-testing')
5355
testImplementation 'junit:junit:4.13.2'
5456
testImplementation 'org.mockito:mockito-core:3.4.6'
5557
testImplementation "com.google.truth:truth:$googleTruthVersion"

appcheck/firebase-appcheck-playintegrity/src/main/java/com/google/firebase/appcheck/playintegrity/FirebaseAppCheckPlayIntegrityRegistrar.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616

1717
import com.google.android.gms.common.annotation.KeepForSdk;
1818
import com.google.firebase.FirebaseApp;
19+
import com.google.firebase.annotations.concurrent.Blocking;
1920
import com.google.firebase.appcheck.playintegrity.internal.PlayIntegrityAppCheckProvider;
2021
import com.google.firebase.components.Component;
2122
import com.google.firebase.components.ComponentRegistrar;
2223
import com.google.firebase.components.Dependency;
24+
import com.google.firebase.components.Qualified;
2325
import com.google.firebase.platforminfo.LibraryVersionComponent;
2426
import java.util.Arrays;
2527
import java.util.List;
28+
import java.util.concurrent.Executor;
2629

2730
/**
2831
* {@link ComponentRegistrar} for setting up FirebaseAppCheck play integrity's dependency injections
@@ -36,12 +39,17 @@ public class FirebaseAppCheckPlayIntegrityRegistrar implements ComponentRegistra
3639

3740
@Override
3841
public List<Component<?>> getComponents() {
42+
Qualified<Executor> blockingExecutor = Qualified.qualified(Blocking.class, Executor.class);
43+
3944
return Arrays.asList(
4045
Component.builder(PlayIntegrityAppCheckProvider.class)
4146
.name(LIBRARY_NAME)
4247
.add(Dependency.required(FirebaseApp.class))
48+
.add(Dependency.required(blockingExecutor))
4349
.factory(
44-
(container) -> new PlayIntegrityAppCheckProvider(container.get(FirebaseApp.class)))
50+
(container) ->
51+
new PlayIntegrityAppCheckProvider(
52+
container.get(FirebaseApp.class), container.get(blockingExecutor)))
4553
.build(),
4654
LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME));
4755
}

appcheck/firebase-appcheck-playintegrity/src/main/java/com/google/firebase/appcheck/playintegrity/internal/PlayIntegrityAppCheckProvider.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
import com.google.android.play.core.integrity.IntegrityTokenRequest;
2525
import com.google.android.play.core.integrity.IntegrityTokenResponse;
2626
import com.google.firebase.FirebaseApp;
27+
import com.google.firebase.annotations.concurrent.Blocking;
2728
import com.google.firebase.appcheck.AppCheckProvider;
2829
import com.google.firebase.appcheck.AppCheckToken;
2930
import com.google.firebase.appcheck.internal.DefaultAppCheckToken;
3031
import com.google.firebase.appcheck.internal.NetworkClient;
3132
import com.google.firebase.appcheck.internal.RetryManager;
32-
import java.util.concurrent.ExecutorService;
33-
import java.util.concurrent.Executors;
33+
import java.util.concurrent.Executor;
3434

3535
public class PlayIntegrityAppCheckProvider implements AppCheckProvider {
3636

@@ -39,17 +39,16 @@ public class PlayIntegrityAppCheckProvider implements AppCheckProvider {
3939
private final String projectNumber;
4040
private final IntegrityManager integrityManager;
4141
private final NetworkClient networkClient;
42-
private final ExecutorService backgroundExecutor;
42+
private final Executor blockingExecutor;
4343
private final RetryManager retryManager;
4444

45-
// TODO(b/258273630): Migrate to go/firebase-android-executors
46-
@SuppressLint("ThreadPoolCreation")
47-
public PlayIntegrityAppCheckProvider(@NonNull FirebaseApp firebaseApp) {
45+
public PlayIntegrityAppCheckProvider(
46+
@NonNull FirebaseApp firebaseApp, @Blocking Executor blockingExecutor) {
4847
this(
4948
firebaseApp.getOptions().getGcmSenderId(),
5049
IntegrityManagerFactory.create(firebaseApp.getApplicationContext()),
5150
new NetworkClient(firebaseApp),
52-
Executors.newCachedThreadPool(),
51+
blockingExecutor,
5352
new RetryManager());
5453
}
5554

@@ -58,12 +57,12 @@ public PlayIntegrityAppCheckProvider(@NonNull FirebaseApp firebaseApp) {
5857
@NonNull String projectNumber,
5958
@NonNull IntegrityManager integrityManager,
6059
@NonNull NetworkClient networkClient,
61-
@NonNull ExecutorService backgroundExecutor,
60+
@NonNull Executor blockingExecutor,
6261
@NonNull RetryManager retryManager) {
6362
this.projectNumber = projectNumber;
6463
this.integrityManager = integrityManager;
6564
this.networkClient = networkClient;
66-
this.backgroundExecutor = backgroundExecutor;
65+
this.blockingExecutor = blockingExecutor;
6766
this.retryManager = retryManager;
6867
}
6968

@@ -78,7 +77,7 @@ public Task<AppCheckToken> getToken() {
7877
ExchangePlayIntegrityTokenRequest request =
7978
new ExchangePlayIntegrityTokenRequest(integrityTokenResponse.token());
8079
return Tasks.call(
81-
backgroundExecutor,
80+
blockingExecutor,
8281
() ->
8382
networkClient.exchangeAttestationForAppCheckToken(
8483
request.toJsonString().getBytes(UTF_8),
@@ -100,7 +99,7 @@ private Task<IntegrityTokenResponse> getPlayIntegrityAttestation() {
10099
new GeneratePlayIntegrityChallengeRequest();
101100
Task<GeneratePlayIntegrityChallengeResponse> generateChallengeTask =
102101
Tasks.call(
103-
backgroundExecutor,
102+
blockingExecutor,
104103
() ->
105104
GeneratePlayIntegrityChallengeResponse.fromJsonString(
106105
networkClient.generatePlayIntegrityChallenge(

0 commit comments

Comments
 (0)