Skip to content

Commit 4c7d4a9

Browse files
committed
Integrate PlayIntegrityAppCheckProvider with Firebase Components.
1 parent c4bee0c commit 4c7d4a9

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
package com.google.firebase.appcheck.playintegrity;
1616

1717
import com.google.android.gms.common.annotation.KeepForSdk;
18+
import com.google.firebase.FirebaseApp;
19+
import com.google.firebase.appcheck.playintegrity.internal.PlayIntegrityAppCheckProvider;
1820
import com.google.firebase.components.Component;
1921
import com.google.firebase.components.ComponentRegistrar;
22+
import com.google.firebase.components.Dependency;
2023
import com.google.firebase.platforminfo.LibraryVersionComponent;
2124
import java.util.Arrays;
2225
import java.util.List;
@@ -33,6 +36,13 @@ public class FirebaseAppCheckPlayIntegrityRegistrar implements ComponentRegistra
3336

3437
@Override
3538
public List<Component<?>> getComponents() {
36-
return Arrays.asList(LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME));
39+
return Arrays.asList(
40+
Component.builder(PlayIntegrityAppCheckProvider.class)
41+
.name(LIBRARY_NAME)
42+
.add(Dependency.required(FirebaseApp.class))
43+
.factory(
44+
(container) -> new PlayIntegrityAppCheckProvider(container.get(FirebaseApp.class)))
45+
.build(),
46+
LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME));
3747
}
3848
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ public static PlayIntegrityAppCheckProviderFactory getInstance() {
4040

4141
@NonNull
4242
@Override
43+
@SuppressWarnings("FirebaseUseExplicitDependencies")
4344
public AppCheckProvider create(@NonNull FirebaseApp firebaseApp) {
44-
return new PlayIntegrityAppCheckProvider(firebaseApp);
45+
return firebaseApp.get(PlayIntegrityAppCheckProvider.class);
4546
}
4647
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
15+
package com.google.firebase.appcheck.playintegrity;
16+
17+
import static com.google.common.truth.Truth.assertThat;
18+
19+
import com.google.firebase.FirebaseApp;
20+
import com.google.firebase.components.Component;
21+
import com.google.firebase.components.Dependency;
22+
import java.util.List;
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.robolectric.RobolectricTestRunner;
26+
27+
/** Tests for {@link FirebaseAppCheckPlayIntegrityRegistrar}. */
28+
@RunWith(RobolectricTestRunner.class)
29+
public class FirebaseAppCheckPlayIntegrityRegistrarTest {
30+
@Test
31+
public void testGetComponents() {
32+
FirebaseAppCheckPlayIntegrityRegistrar registrar = new FirebaseAppCheckPlayIntegrityRegistrar();
33+
List<Component<?>> components = registrar.getComponents();
34+
assertThat(components).isNotEmpty();
35+
assertThat(components).hasSize(2);
36+
Component<?> appCheckPlayIntegrityComponent = components.get(0);
37+
assertThat(appCheckPlayIntegrityComponent.getDependencies())
38+
.containsExactly(Dependency.required(FirebaseApp.class));
39+
assertThat(appCheckPlayIntegrityComponent.isLazy()).isTrue();
40+
}
41+
}

0 commit comments

Comments
 (0)