-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathcommon_android.h
More file actions
80 lines (62 loc) · 2.79 KB
/
common_android.h
File metadata and controls
80 lines (62 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef FIREBASE_APP_CHECK_SRC_ANDROID_COMMON_ANDROID_H_
#define FIREBASE_APP_CHECK_SRC_ANDROID_COMMON_ANDROID_H_
#include <jni.h>
#include <string>
#include "app/src/app_common.h"
#include "app/src/util_android.h"
#include "app_check/src/include/firebase/app_check.h"
#include "firebase/app_check.h"
namespace firebase {
namespace app_check {
namespace internal {
// Used to setup the cache of AppCheckProvider interface method IDs to reduce
// time spent looking up methods by string.
// clang-format off
#define APP_CHECK_PROVIDER_METHODS(X) \
X(GetToken, "getToken", \
"()Lcom/google/android/gms/tasks/Task;")
// clang-format on
METHOD_LOOKUP_DECLARATION(app_check_provider, APP_CHECK_PROVIDER_METHODS)
// Cache the method ids so we don't have to look up JNI functions by name.
bool CacheCommonAndroidMethodIds(JNIEnv* env, jobject activity);
// Release app check classes cached by CacheCommonAndroidMethodIds().
void ReleaseCommonAndroidClasses(JNIEnv* env);
JNIEnv* GetJniEnv();
AppCheckToken CppTokenFromAndroidToken(JNIEnv* env, jobject token_obj);
// A generic class to wrap a java AppCheckProvider.
class AndroidAppCheckProvider : public AppCheckProvider {
public:
explicit AndroidAppCheckProvider(jobject debug_provider);
virtual ~AndroidAppCheckProvider();
/// Fetches an AppCheckToken and then calls the provided callback method with
/// the token or with an error code and error message.
void GetToken(std::function<void(AppCheckToken, int, const std::string&)>
completion_callback) override;
/// Fetches an AppCheckToken via a fallback method to the GetToken. The
/// current Android implementation does not support limited use tokens. For
/// custom App Check providers.
void GetLimitedUseToken(
std::function<void(AppCheckToken, int, const std::string&)>
completion_callback) override;
private:
jobject android_provider_;
// String to be used when registering for JNI task callbacks.
std::string jni_task_id_;
};
} // namespace internal
} // namespace app_check
} // namespace firebase
#endif // FIREBASE_APP_CHECK_SRC_ANDROID_COMMON_ANDROID_H_