Skip to content

Commit d9a5a1b

Browse files
authored
Android AppCheck main implementation (#1220)
AppCheck android implementation of main classes. - includes Java factory and provider to wrap c++ factory and provider
1 parent 6bf9316 commit d9a5a1b

File tree

15 files changed

+522
-31
lines changed

15 files changed

+522
-31
lines changed

Android/firebase_dependencies.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def firebaseResourceDependenciesMap = [
4848
'app' : [':app:app_resources',
4949
':app:google_api_resources',
5050
':app:invites_resources'],
51+
'app_check' : [':app_check:app_check_resources'],
5152
'admob' : [':admob:admob_resources'],
5253
'auth' : [':auth:auth_resources'],
5354
'database' : [':database:database_resources'],

app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ set(app_android_HDRS
312312
src/invites/android/invites_android_helper.h
313313
src/invites/android/invites_receiver_internal_android.h)
314314
set(app_ios_HDRS
315+
src/app_ios.h
315316
src/invites/ios/invites_receiver_internal_ios.h)
316317
set(app_desktop_HDRS
317318
src/invites/stub/invites_receiver_internal_stub.h)

app/src/app_android.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ JOBJECT_REFERENCE(AppInternal);
5757
X(GetInstanceByName, "getInstance", \
5858
"(Ljava/lang/String;)Lcom/google/firebase/FirebaseApp;", \
5959
util::kMethodTypeStatic), \
60+
X(GetName, "getName", "()Ljava/lang/String;", util::kMethodTypeInstance), \
6061
X(GetOptions, "getOptions", "()Lcom/google/firebase/FirebaseOptions;", \
6162
util::kMethodTypeInstance), \
6263
X(Delete, "delete", "()V", util::kMethodTypeInstance), \

app_check/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,17 @@ set(common_SRCS
2626
src/include/firebase/app_check/app_attest_provider.h
2727
)
2828

29+
# Run gradle command to make jar
30+
firebase_cpp_gradle(":app_check:app_check_resources:generateDexJarRelease"
31+
"${CMAKE_CURRENT_LIST_DIR}/app_check_resources/build/app_check_resources_lib.jar")
32+
binary_to_array("app_check_resources"
33+
"${CMAKE_CURRENT_LIST_DIR}/app_check_resources/build/app_check_resources_lib.jar"
34+
"firebase_app_check"
35+
"${FIREBASE_GEN_FILE_DIR}/app_check")
36+
2937
# Source files used by the Android implementation.
3038
set(android_SRCS
39+
${app_check_resources_source}
3140
src/android/app_check_android.cc
3241
src/android/app_check_android.h
3342
src/android/common_android.cc
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright 2023 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+
buildscript {
16+
repositories {
17+
google()
18+
mavenCentral()
19+
}
20+
dependencies {
21+
classpath 'com.android.tools.build:gradle:3.3.3'
22+
classpath 'com.google.gms:google-services:4.2.0'
23+
}
24+
}
25+
allprojects {
26+
repositories {
27+
google()
28+
mavenCentral()
29+
}
30+
}
31+
32+
apply plugin: 'com.android.library'
33+
34+
android {
35+
compileOptions {
36+
sourceCompatibility 1.8
37+
targetCompatibility 1.8
38+
}
39+
compileSdkVersion 28
40+
41+
sourceSets {
42+
main {
43+
manifest.srcFile '../../android_build_files/AndroidManifest.xml'
44+
java {
45+
srcDirs = ['../src_java/com/google/firebase/appcheck/internal/cpp']
46+
}
47+
}
48+
}
49+
}
50+
51+
dependencies {
52+
implementation platform('com.google.firebase:firebase-bom:31.2.0')
53+
implementation 'com.google.firebase:firebase-appcheck'
54+
}
55+
56+
afterEvaluate {
57+
generateReleaseBuildConfig.enabled = false
58+
}
59+
60+
apply from: "$rootDir/android_build_files/extract_and_dex.gradle"
61+
extractAndDexAarFile('app_check_resources')

app_check/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ dependencies {
8080
implementation project(':app')
8181
}
8282
apply from: "$rootDir/android_build_files/android_abis.gradle"
83+
apply from: "$rootDir/android_build_files/extract_and_dex.gradle"
8384
apply from: "$rootDir/android_build_files/generate_proguard.gradle"
8485
project.afterEvaluate {
8586
generateProguardFile('app_check')
87+
setupDexDependencies(':app_check:app_check_resources')
8688
}

app_check/integration_test/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ android {
6363
"-DFIREBASE_INCLUDE_LIBRARY_DEFAULT=OFF",
6464
"-DFIREBASE_INCLUDE_APP_CHECK=ON",
6565
"-DFIREBASE_INCLUDE_AUTH=ON",
66-
"-DFIREBASE_INCLUDE_DATABASE=ON"
66+
"-DFIREBASE_INCLUDE_DATABASE=ON",
67+
"-DFIREBASE_INCLUDE_STORAGE=ON"
6768
}
6869
}
6970
externalNativeBuild.cmake {
@@ -83,6 +84,7 @@ firebaseCpp.dependencies {
8384
appCheck
8485
auth
8586
database
87+
storage
8688
}
8789

8890
apply plugin: 'com.google.gms.google-services'

app_check/integration_test/src/integration_test.cc

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,6 @@ TEST_F(FirebaseAppCheckTest, TestInitializeAndTerminate) {
409409
InitializeApp();
410410
}
411411

412-
// Android does not yet implement the main app check methods
413-
#if !FIREBASE_PLATFORM_ANDROID
414412
TEST_F(FirebaseAppCheckTest, TestGetTokenForcingRefresh) {
415413
InitializeAppCheckWithDebug();
416414
InitializeApp();
@@ -443,10 +441,7 @@ TEST_F(FirebaseAppCheckTest, TestGetTokenForcingRefresh) {
443441
EXPECT_NE(future.result()->expire_time_millis,
444442
future3.result()->expire_time_millis);
445443
}
446-
#endif // !FIREBASE_PLATFORM_ANDROID
447444

448-
// Android does not yet implement the main app check methods
449-
#if !FIREBASE_PLATFORM_ANDROID
450445
TEST_F(FirebaseAppCheckTest, TestGetTokenLastResult) {
451446
InitializeAppCheckWithDebug();
452447
InitializeApp();
@@ -464,9 +459,8 @@ TEST_F(FirebaseAppCheckTest, TestGetTokenLastResult) {
464459
EXPECT_EQ(future.result()->expire_time_millis,
465460
future2.result()->expire_time_millis);
466461
}
467-
#endif // !FIREBASE_PLATFORM_ANDROID
468462

469-
// Android does not yet implement the main app check methods
463+
// Android does not yet implement token changed listeners
470464
#if !FIREBASE_PLATFORM_ANDROID
471465
TEST_F(FirebaseAppCheckTest, TestAddTokenChangedListener) {
472466
InitializeAppCheckWithDebug();
@@ -489,7 +483,7 @@ TEST_F(FirebaseAppCheckTest, TestAddTokenChangedListener) {
489483
}
490484
#endif // !FIREBASE_PLATFORM_ANDROID
491485

492-
// Android does not yet implement the main app check methods
486+
// Android does not yet implement token changed listeners
493487
#if !FIREBASE_PLATFORM_ANDROID
494488
TEST_F(FirebaseAppCheckTest, TestRemoveTokenChangedListener) {
495489
InitializeAppCheckWithDebug();
@@ -524,12 +518,6 @@ TEST_F(FirebaseAppCheckTest, TestDebugProviderValidToken) {
524518
ASSERT_NE(factory, nullptr);
525519
InitializeAppCheckWithDebug();
526520
InitializeApp();
527-
// TODO(almostmatt): Once app initialization automatically initializes
528-
// AppCheck, this test will no longer need to explicitly get an instance of
529-
// AppCheck.
530-
::firebase::app_check::AppCheck* app_check =
531-
::firebase::app_check::AppCheck::GetInstance(app_);
532-
ASSERT_NE(app_check, nullptr);
533521

534522
firebase::app_check::AppCheckProvider* provider =
535523
factory->CreateProvider(app_);
@@ -611,6 +599,7 @@ TEST_F(FirebaseAppCheckTest, TestPlayIntegrityProvider) {
611599
#if FIREBASE_PLATFORM_ANDROID
612600
ASSERT_NE(factory, nullptr);
613601
InitializeApp();
602+
614603
firebase::app_check::AppCheckProvider* provider =
615604
factory->CreateProvider(app_);
616605
EXPECT_NE(provider, nullptr);
@@ -738,6 +727,9 @@ TEST_F(FirebaseAppCheckTest, TestStorageReadFile) {
738727
LogDebug(" buffer: %s", buffer);
739728
}
740729

730+
// Android doesn't yet work correctly when AppCheck provider factory is null
731+
// TODO(almostmatt): Investigate and fix this test for android
732+
#if !FIREBASE_PLATFORM_ANDROID
741733
TEST_F(FirebaseAppCheckTest, TestStorageReadFileUnauthenticated) {
742734
// Don't set up AppCheck
743735
InitializeAppAuthStorage();
@@ -751,5 +743,6 @@ TEST_F(FirebaseAppCheckTest, TestStorageReadFileUnauthenticated) {
751743
firebase::storage::kErrorUnauthenticated);
752744
LogDebug(" buffer: %s", buffer);
753745
}
746+
#endif // !FIREBASE_PLATFORM_ANDROID
754747

755748
} // namespace firebase_testapp_automated

0 commit comments

Comments
 (0)