@react-native-firebase/app 23.8.0 → 23.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1547 -0
- package/RNFBApp.podspec +49 -0
- package/android/.editorconfig +10 -0
- package/android/build.gradle +129 -0
- package/android/firebase-json.gradle +73 -0
- package/android/gradle.properties +2 -0
- package/android/lint.xml +5 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +24 -0
- package/android/src/main/java/io/invertase/firebase/app/.gitkeep +0 -0
- package/android/src/main/java/io/invertase/firebase/common/TaskExecutorService.java +124 -0
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebaseModule.java +62 -0
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebasePreferences.java +91 -0
- package/android/src/main/java/io/invertase/firebase/interfaces/.gitkeep +0 -0
- package/android/src/reactnative/AndroidManifest.xml +2 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseApp.java +46 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppInitProvider.java +22 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppModule.java +186 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackage.java +49 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java +35 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseVersion.java +22 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.java +191 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEvent.java +53 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.java +151 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseInitProvider.java +78 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseJSON.java +107 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseMeta.java +93 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java +146 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebasePreferences.java +88 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java +440 -0
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/ContextProvider.java +30 -0
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/NativeError.java +32 -0
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/NativeEvent.java +28 -0
- package/android/src/reactnative/java/io/invertase/firebase/utils/ReactNativeFirebaseUtilsModule.java +191 -0
- package/app.plugin.js +1 -0
- package/dist/commonjs/version.js +1 -1
- package/dist/module/version.js +1 -1
- package/dist/typescript/commonjs/lib/modular.d.ts +1 -1
- package/dist/typescript/commonjs/lib/version.d.ts +1 -1
- package/dist/typescript/module/lib/modular.d.ts +1 -1
- package/dist/typescript/module/lib/version.d.ts +1 -1
- package/firebase-schema.json +149 -0
- package/firebase_json.rb +72 -0
- package/ios/RNFBApp/RCTConvert+FIRApp.h +23 -0
- package/ios/RNFBApp/RCTConvert+FIRApp.m +31 -0
- package/ios/RNFBApp/RCTConvert+FIROptions.h +23 -0
- package/ios/RNFBApp/RCTConvert+FIROptions.m +36 -0
- package/ios/RNFBApp/RNFBAppModule.h +28 -0
- package/ios/RNFBApp/RNFBAppModule.m +305 -0
- package/ios/RNFBApp/RNFBJSON.h +36 -0
- package/ios/RNFBApp/RNFBJSON.m +99 -0
- package/ios/RNFBApp/RNFBMeta.h +30 -0
- package/ios/RNFBApp/RNFBMeta.m +61 -0
- package/ios/RNFBApp/RNFBNullSentinelInterceptor.h +47 -0
- package/ios/RNFBApp/RNFBNullSentinelInterceptor.m +74 -0
- package/ios/RNFBApp/RNFBPreferences.h +44 -0
- package/ios/RNFBApp/RNFBPreferences.m +94 -0
- package/ios/RNFBApp/RNFBRCTEventEmitter.h +73 -0
- package/ios/RNFBApp/RNFBRCTEventEmitter.m +151 -0
- package/ios/RNFBApp/RNFBSharedUtils.h +67 -0
- package/ios/RNFBApp/RNFBSharedUtils.m +285 -0
- package/ios/RNFBApp/RNFBUtilsModule.h +30 -0
- package/ios/RNFBApp/RNFBUtilsModule.m +100 -0
- package/ios/RNFBApp/RNFBVersion.h +20 -0
- package/ios/RNFBApp/RNFBVersion.m +21 -0
- package/ios/RNFBApp.xcodeproj/project.pbxproj +411 -0
- package/ios/RNFBApp.xcodeproj/xcshareddata/IDETemplateMacros.plist +24 -0
- package/ios_config.sh +269 -0
- package/lib/version.ts +1 -1
- package/package.json +4 -11
- package/plugin/build/android/applyPlugin.d.ts +6 -0
- package/plugin/build/android/applyPlugin.js +29 -0
- package/plugin/build/android/buildscriptDependency.d.ts +6 -0
- package/plugin/build/android/buildscriptDependency.js +31 -0
- package/plugin/build/android/constants.d.ts +4 -0
- package/plugin/build/android/constants.js +8 -0
- package/plugin/build/android/copyGoogleServices.d.ts +5 -0
- package/plugin/build/android/copyGoogleServices.js +33 -0
- package/plugin/build/android/index.d.ts +4 -0
- package/plugin/build/android/index.js +9 -0
- package/plugin/build/index.d.ts +3 -0
- package/plugin/build/index.js +21 -0
- package/plugin/build/ios/appDelegate.d.ts +6 -0
- package/plugin/build/ios/appDelegate.js +116 -0
- package/plugin/build/ios/googleServicesPlist.d.ts +7 -0
- package/plugin/build/ios/googleServicesPlist.js +42 -0
- package/plugin/build/ios/index.d.ts +3 -0
- package/plugin/build/ios/index.js +7 -0
- package/plugin/src/android/applyPlugin.ts +30 -0
- package/plugin/src/android/buildscriptDependency.ts +33 -0
- package/plugin/src/android/constants.ts +7 -0
- package/plugin/src/android/copyGoogleServices.ts +36 -0
- package/plugin/src/android/index.ts +5 -0
- package/plugin/src/index.ts +27 -0
- package/plugin/src/ios/appDelegate.ts +140 -0
- package/plugin/src/ios/googleServicesPlist.ts +55 -0
- package/plugin/src/ios/index.ts +4 -0
- package/plugin/tsconfig.json +9 -0
- package/plugin/tsconfig.tsbuildinfo +1 -0
- package/react-native.config.js +19 -0
- package/tsconfig.json +10 -0
package/RNFBApp.podspec
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require './firebase_json'
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
firebase_sdk_version = package['sdkVersions']['ios']['firebase']
|
|
5
|
+
firebase_ios_target = package['sdkVersions']['ios']['iosTarget']
|
|
6
|
+
firebase_macos_target = package['sdkVersions']['ios']['macosTarget']
|
|
7
|
+
firebase_tvos_target = package['sdkVersions']['ios']['tvosTarget']
|
|
8
|
+
|
|
9
|
+
Pod::Spec.new do |s|
|
|
10
|
+
s.name = "RNFBApp"
|
|
11
|
+
s.version = package["version"]
|
|
12
|
+
s.description = package["description"]
|
|
13
|
+
s.summary = <<-DESC
|
|
14
|
+
A well tested feature rich Firebase implementation for React Native, supporting iOS & Android.
|
|
15
|
+
DESC
|
|
16
|
+
s.homepage = "http://invertase.io/oss/react-native-firebase"
|
|
17
|
+
s.license = package['license']
|
|
18
|
+
s.authors = "Invertase Limited"
|
|
19
|
+
s.source = { :git => "https://github.com/invertase/react-native-firebase.git", :tag => "v#{s.version}" }
|
|
20
|
+
s.social_media_url = 'http://twitter.com/invertaseio'
|
|
21
|
+
s.ios.deployment_target = firebase_ios_target
|
|
22
|
+
s.macos.deployment_target = firebase_macos_target
|
|
23
|
+
s.tvos.deployment_target = firebase_tvos_target
|
|
24
|
+
s.cocoapods_version = '>= 1.12.0'
|
|
25
|
+
s.source_files = "ios/**/*.{h,m}"
|
|
26
|
+
|
|
27
|
+
# React Native dependencies
|
|
28
|
+
s.dependency 'React-Core'
|
|
29
|
+
|
|
30
|
+
if (ENV.include?('FIREBASE_SDK_VERSION'))
|
|
31
|
+
Pod::UI.puts "#{s.name}: Found Firebase SDK version in environment '#{ENV['FIREBASE_SDK_VERSION']}'"
|
|
32
|
+
$FirebaseSDKVersion = ENV['FIREBASE_SDK_VERSION']
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
if defined?($FirebaseSDKVersion)
|
|
36
|
+
Pod::UI.puts "#{s.name}: Using user specified Firebase SDK version '#{$FirebaseSDKVersion}'"
|
|
37
|
+
firebase_sdk_version = $FirebaseSDKVersion
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Firebase dependencies
|
|
41
|
+
s.dependency 'Firebase/CoreOnly', firebase_sdk_version
|
|
42
|
+
|
|
43
|
+
if defined?($RNFirebaseAsStaticFramework)
|
|
44
|
+
Pod::UI.puts "#{s.name}: Using overridden static_framework value of '#{$RNFirebaseAsStaticFramework}'"
|
|
45
|
+
s.static_framework = $RNFirebaseAsStaticFramework
|
|
46
|
+
else
|
|
47
|
+
s.static_framework = false
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import com.android.Version
|
|
2
|
+
import io.invertase.gradle.common.PackageJson
|
|
3
|
+
import org.gradle.internal.jvm.Jvm
|
|
4
|
+
|
|
5
|
+
buildscript {
|
|
6
|
+
// The Android Gradle plugin is only required when opening the android folder stand-alone.
|
|
7
|
+
// This avoids unnecessary downloads and potential conflicts when the library is included as a
|
|
8
|
+
// module dependency in an application project.
|
|
9
|
+
if (project == rootProject) {
|
|
10
|
+
repositories {
|
|
11
|
+
google()
|
|
12
|
+
mavenCentral()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
dependencies {
|
|
16
|
+
classpath("com.android.tools.build:gradle:8.4.0")
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
plugins {
|
|
22
|
+
id "io.invertase.gradle.build" version "1.5"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
def packageJson = PackageJson.getForProject(project)
|
|
26
|
+
def firebaseBomVersion = packageJson['sdkVersions']['android']['firebase']
|
|
27
|
+
def playServicesAuthVersion = packageJson['sdkVersions']['android']['playServicesAuth']
|
|
28
|
+
def jsonMinSdk = packageJson['sdkVersions']['android']['minSdk']
|
|
29
|
+
def jsonTargetSdk = packageJson['sdkVersions']['android']['targetSdk']
|
|
30
|
+
def jsonCompileSdk = packageJson['sdkVersions']['android']['compileSdk']
|
|
31
|
+
|
|
32
|
+
project.ext {
|
|
33
|
+
set('react-native', [
|
|
34
|
+
versions: [
|
|
35
|
+
android : [
|
|
36
|
+
minSdk : jsonMinSdk,
|
|
37
|
+
targetSdk : jsonTargetSdk,
|
|
38
|
+
compileSdk: jsonCompileSdk,
|
|
39
|
+
],
|
|
40
|
+
|
|
41
|
+
firebase: [
|
|
42
|
+
bom: firebaseBomVersion,
|
|
43
|
+
],
|
|
44
|
+
|
|
45
|
+
play : [
|
|
46
|
+
"play-services-auth": playServicesAuthVersion,
|
|
47
|
+
],
|
|
48
|
+
],
|
|
49
|
+
])
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
apply from: file('./firebase-json.gradle')
|
|
53
|
+
|
|
54
|
+
// If data collection isn't specifically disabled, default is enabled
|
|
55
|
+
String dataCollectionDefaultEnabled = 'true'
|
|
56
|
+
|
|
57
|
+
if (rootProject.ext && rootProject.ext.firebaseJson) {
|
|
58
|
+
if (rootProject.ext.firebaseJson.isFlagEnabled('app_data_collection_default_enabled', true) == false) {
|
|
59
|
+
dataCollectionDefaultEnabled = 'false'
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
android {
|
|
64
|
+
def agpVersion = Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
|
|
65
|
+
if (agpVersion >= 7) {
|
|
66
|
+
namespace = 'io.invertase.firebase'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
defaultConfig {
|
|
70
|
+
multiDexEnabled = true
|
|
71
|
+
manifestPlaceholders = [
|
|
72
|
+
firebaseJsonDataCollectionDefaultEnabled: dataCollectionDefaultEnabled
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
buildFeatures {
|
|
77
|
+
// AGP 8 no longer builds config by default
|
|
78
|
+
buildConfig = true
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
lintOptions {
|
|
82
|
+
disable 'GradleCompatible'
|
|
83
|
+
abortOnError = false
|
|
84
|
+
}
|
|
85
|
+
if (agpVersion < 8) {
|
|
86
|
+
compileOptions {
|
|
87
|
+
sourceCompatibility = JavaVersion.VERSION_11
|
|
88
|
+
targetCompatibility = JavaVersion.VERSION_11
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
sourceSets {
|
|
93
|
+
main {
|
|
94
|
+
java.srcDirs = ['src/main/java', 'src/reactnative/java']
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
repositories {
|
|
100
|
+
google()
|
|
101
|
+
mavenCentral()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
dependencies {
|
|
105
|
+
implementation platform("com.google.firebase:firebase-bom:${ReactNative.ext.getVersion("firebase", "bom")}")
|
|
106
|
+
implementation "com.google.firebase:firebase-common"
|
|
107
|
+
implementation "com.google.android.gms:play-services-auth:${ReactNative.ext.getVersion("play", "play-services-auth")}"
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
def jvmVersion = Jvm.current().javaVersion?.majorVersion
|
|
111
|
+
// if it cannot get version, just allow it to pass. This is just a helper for developers
|
|
112
|
+
if ((jvmVersion?.toInteger() ?: 17) < 17) {
|
|
113
|
+
println("\n\n\n")
|
|
114
|
+
println("**************************************************************************************************************")
|
|
115
|
+
println("\n\n\n")
|
|
116
|
+
println("ERROR: React Native Firebase builds with a minimum JVM version 17. We test with JVM 17 and 21.")
|
|
117
|
+
println(" Incompatible major version detected: '" + jvmVersion + "'")
|
|
118
|
+
println("\n\n\n")
|
|
119
|
+
println(" If you receive this error because you want to use a different JDK, we may accept PRs to support new versions.")
|
|
120
|
+
println("\n\n\n")
|
|
121
|
+
println("**************************************************************************************************************")
|
|
122
|
+
println("\n\n\n")
|
|
123
|
+
System.exit(1)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
ReactNative.shared.applyPackageVersion()
|
|
127
|
+
ReactNative.shared.applyDefaultExcludes()
|
|
128
|
+
ReactNative.module.applyAndroidVersions()
|
|
129
|
+
ReactNative.module.applyReactNativeDependency("api")
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/* groovylint-disable CatchException, CompileStatic, DuplicateStringLiteral, JavaIoPackageAccess */
|
|
2
|
+
import groovy.json.JsonOutput
|
|
3
|
+
import groovy.json.JsonSlurper
|
|
4
|
+
|
|
5
|
+
String fileName = 'firebase.json'
|
|
6
|
+
String jsonRoot = 'react-native'
|
|
7
|
+
|
|
8
|
+
File jsonFile = null
|
|
9
|
+
File parentDir = rootProject.projectDir
|
|
10
|
+
|
|
11
|
+
for (int i = 0; i <= 3; i++) {
|
|
12
|
+
if (parentDir == null) { break }
|
|
13
|
+
parentDir = parentDir.parentFile
|
|
14
|
+
if (parentDir != null) {
|
|
15
|
+
jsonFile = new File(parentDir, fileName)
|
|
16
|
+
if (jsonFile.exists()) { break }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (jsonFile?.exists()) {
|
|
21
|
+
rootProject.logger.info ":${project.name} firebase.json found at ${jsonFile}"
|
|
22
|
+
Object json = null
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
json = new JsonSlurper().parseText(jsonFile.text)
|
|
26
|
+
} catch (Exception ignored) {
|
|
27
|
+
rootProject.logger.warn ":${project.name} failed to parse firebase.json found at ${jsonFile}."
|
|
28
|
+
rootProject.logger.warn ignored.toString()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (json && json[jsonRoot]) {
|
|
32
|
+
String jsonStr = JsonOutput.toJson(JsonOutput.toJson(json[jsonRoot]))
|
|
33
|
+
|
|
34
|
+
rootProject.ext.firebaseJson = [
|
|
35
|
+
raw: json[jsonRoot],
|
|
36
|
+
isDefined: { key ->
|
|
37
|
+
return (json[jsonRoot] != null && json[jsonRoot][key] != null)
|
|
38
|
+
},
|
|
39
|
+
isFlagEnabled: { key, defaultValue ->
|
|
40
|
+
if (json[jsonRoot] == null || json[jsonRoot][key] == null) { return defaultValue }
|
|
41
|
+
return json[jsonRoot][key] == true
|
|
42
|
+
},
|
|
43
|
+
getStringValue: { key, defaultValue ->
|
|
44
|
+
if (json[jsonRoot] == null) { return defaultValue }
|
|
45
|
+
return json[jsonRoot][key] ? json[jsonRoot][key] : defaultValue
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
rootProject.logger
|
|
50
|
+
.info ":${project.name} found react-native json root in firebase.json, creating firebase build config"
|
|
51
|
+
android {
|
|
52
|
+
defaultConfig {
|
|
53
|
+
buildConfigField 'String', 'FIREBASE_JSON_RAW', jsonStr
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
rootProject.ext.firebaseJson = false
|
|
58
|
+
rootProject.logger.info ":${project.name} firebase.json found with no react-native config, skipping"
|
|
59
|
+
android {
|
|
60
|
+
defaultConfig {
|
|
61
|
+
buildConfigField 'String', 'FIREBASE_JSON_RAW', '"{}"'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
rootProject.ext.firebaseJson = false
|
|
67
|
+
rootProject.logger.info ":${project.name} no firebase.json found, skipping"
|
|
68
|
+
android {
|
|
69
|
+
defaultConfig {
|
|
70
|
+
buildConfigField 'String', 'FIREBASE_JSON_RAW', '"{}"'
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
package/android/lint.xml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rootProject.name = '@react-native-firebase_app'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
xmlns:tools="http://schemas.android.com/tools"
|
|
4
|
+
package="io.invertase.firebase">
|
|
5
|
+
|
|
6
|
+
<application>
|
|
7
|
+
<meta-data android:name="app_data_collection_default_enabled" android:value="${firebaseJsonDataCollectionDefaultEnabled}"/>
|
|
8
|
+
<service
|
|
9
|
+
android:name="com.google.firebase.components.ComponentDiscoveryService"
|
|
10
|
+
android:directBootAware="true"
|
|
11
|
+
android:exported="false"
|
|
12
|
+
tools:targetApi="n"
|
|
13
|
+
>
|
|
14
|
+
<meta-data
|
|
15
|
+
android:name="com.google.firebase.components:io.invertase.firebase.app.ReactNativeFirebaseAppRegistrar"
|
|
16
|
+
android:value="com.google.firebase.components.ComponentRegistrar" />
|
|
17
|
+
</service>
|
|
18
|
+
<provider
|
|
19
|
+
android:name="io.invertase.firebase.app.ReactNativeFirebaseAppInitProvider"
|
|
20
|
+
android:authorities="${applicationId}.reactnativefirebaseappinitprovider"
|
|
21
|
+
android:exported="false"
|
|
22
|
+
android:initOrder="99" /> <!-- Firebase = 100, using 99 to run after Firebase initialises (highest first) -->
|
|
23
|
+
</application>
|
|
24
|
+
</manifest>
|
|
File without changes
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
package io.invertase.firebase.common;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import java.util.ArrayList;
|
|
21
|
+
import java.util.HashMap;
|
|
22
|
+
import java.util.List;
|
|
23
|
+
import java.util.Map;
|
|
24
|
+
import java.util.concurrent.ExecutorService;
|
|
25
|
+
import java.util.concurrent.Executors;
|
|
26
|
+
import java.util.concurrent.RejectedExecutionHandler;
|
|
27
|
+
import java.util.concurrent.SynchronousQueue;
|
|
28
|
+
import java.util.concurrent.ThreadPoolExecutor;
|
|
29
|
+
import java.util.concurrent.TimeUnit;
|
|
30
|
+
|
|
31
|
+
public class TaskExecutorService {
|
|
32
|
+
private static final String MAXIMUM_POOL_SIZE_KEY = "android_task_executor_maximum_pool_size";
|
|
33
|
+
private static final String KEEP_ALIVE_SECONDS_KEY = "android_task_executor_keep_alive_seconds";
|
|
34
|
+
|
|
35
|
+
private final String name;
|
|
36
|
+
private final int maximumPoolSize;
|
|
37
|
+
private final int keepAliveSeconds;
|
|
38
|
+
private static final Map<String, ExecutorService> executors = new HashMap<>();
|
|
39
|
+
|
|
40
|
+
TaskExecutorService(String name) {
|
|
41
|
+
this.name = name;
|
|
42
|
+
ReactNativeFirebaseJSON json = ReactNativeFirebaseJSON.getSharedInstance();
|
|
43
|
+
this.maximumPoolSize = json.getIntValue(MAXIMUM_POOL_SIZE_KEY, 1);
|
|
44
|
+
this.keepAliveSeconds = json.getIntValue(KEEP_ALIVE_SECONDS_KEY, 3);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public ExecutorService getExecutor() {
|
|
48
|
+
boolean isTransactional = maximumPoolSize <= 1;
|
|
49
|
+
return getExecutor(isTransactional, "");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public ExecutorService getTransactionalExecutor() {
|
|
53
|
+
return getExecutor(true, "");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public ExecutorService getTransactionalExecutor(String identifier) {
|
|
57
|
+
String executorIdentifier = maximumPoolSize != 0 ? identifier : "";
|
|
58
|
+
return getExecutor(true, executorIdentifier);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public ExecutorService getExecutor(boolean isTransactional, String identifier) {
|
|
62
|
+
String executorName = getExecutorName(isTransactional, identifier);
|
|
63
|
+
synchronized (executors) {
|
|
64
|
+
ExecutorService existingExecutor = executors.get(executorName);
|
|
65
|
+
if (existingExecutor == null) {
|
|
66
|
+
ExecutorService newExecutor = getNewExecutor(isTransactional);
|
|
67
|
+
executors.put(executorName, newExecutor);
|
|
68
|
+
return newExecutor;
|
|
69
|
+
}
|
|
70
|
+
return existingExecutor;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private ExecutorService getNewExecutor(boolean isTransactional) {
|
|
75
|
+
if (isTransactional) {
|
|
76
|
+
return Executors.newSingleThreadExecutor();
|
|
77
|
+
} else {
|
|
78
|
+
ThreadPoolExecutor threadPoolExecutor =
|
|
79
|
+
new ThreadPoolExecutor(
|
|
80
|
+
0, maximumPoolSize, keepAliveSeconds, TimeUnit.SECONDS, new SynchronousQueue<>());
|
|
81
|
+
threadPoolExecutor.setRejectedExecutionHandler(executeInFallback);
|
|
82
|
+
return threadPoolExecutor;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private final RejectedExecutionHandler executeInFallback =
|
|
87
|
+
(r, executor) -> {
|
|
88
|
+
if (executor.isShutdown() || executor.isTerminated() || executor.isTerminating()) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
ExecutorService fallbackExecutor = getTransactionalExecutor();
|
|
92
|
+
fallbackExecutor.execute(r);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
public String getExecutorName(boolean isTransactional, String identifier) {
|
|
96
|
+
if (isTransactional) {
|
|
97
|
+
return name + "TransactionalExecutor" + identifier;
|
|
98
|
+
}
|
|
99
|
+
return name + "Executor" + identifier;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public void shutdown() {
|
|
103
|
+
synchronized (executors) {
|
|
104
|
+
List<String> existingExecutorNames = new ArrayList<>(executors.keySet());
|
|
105
|
+
for (String executorName : existingExecutorNames) {
|
|
106
|
+
if (!executorName.startsWith(name)) {
|
|
107
|
+
executors.remove(executorName);
|
|
108
|
+
} else {
|
|
109
|
+
removeExecutor(executorName);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public void removeExecutor(String executorName) {
|
|
116
|
+
synchronized (executors) {
|
|
117
|
+
ExecutorService existingExecutor = executors.get(executorName);
|
|
118
|
+
if (existingExecutor != null) {
|
|
119
|
+
existingExecutor.shutdownNow();
|
|
120
|
+
executors.remove(executorName);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
package io.invertase.firebase.common;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.content.Context;
|
|
21
|
+
import java.util.HashMap;
|
|
22
|
+
import java.util.Map;
|
|
23
|
+
import java.util.concurrent.ExecutorService;
|
|
24
|
+
import javax.annotation.OverridingMethodsMustInvokeSuper;
|
|
25
|
+
|
|
26
|
+
public class UniversalFirebaseModule {
|
|
27
|
+
private final TaskExecutorService executorService;
|
|
28
|
+
|
|
29
|
+
private final Context context;
|
|
30
|
+
private final String serviceName;
|
|
31
|
+
|
|
32
|
+
public UniversalFirebaseModule(Context context, String serviceName) {
|
|
33
|
+
this.context = context;
|
|
34
|
+
this.serviceName = serviceName;
|
|
35
|
+
this.executorService = new TaskExecutorService(getName());
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public Context getContext() {
|
|
39
|
+
return context;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public Context getApplicationContext() {
|
|
43
|
+
return getContext().getApplicationContext();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public ExecutorService getExecutor() {
|
|
47
|
+
return executorService.getExecutor();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public String getName() {
|
|
51
|
+
return "Universal" + serviceName + "Module";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@OverridingMethodsMustInvokeSuper
|
|
55
|
+
public void onTearDown() {
|
|
56
|
+
executorService.shutdown();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public Map<String, Object> getConstants() {
|
|
60
|
+
return new HashMap<>();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
package io.invertase.firebase.common;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.content.Context;
|
|
21
|
+
import android.content.SharedPreferences;
|
|
22
|
+
import io.invertase.firebase.app.ReactNativeFirebaseApp;
|
|
23
|
+
|
|
24
|
+
public class UniversalFirebasePreferences {
|
|
25
|
+
private static final String PREFERENCES_FILE = "io.invertase.firebase";
|
|
26
|
+
private static UniversalFirebasePreferences sharedInstance = new UniversalFirebasePreferences();
|
|
27
|
+
private SharedPreferences preferences;
|
|
28
|
+
|
|
29
|
+
public static UniversalFirebasePreferences getSharedInstance() {
|
|
30
|
+
return sharedInstance;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public boolean contains(String key) {
|
|
34
|
+
return getPreferences().contains(key);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Boolean
|
|
38
|
+
public void setBooleanValue(String key, boolean value) {
|
|
39
|
+
getPreferences().edit().putBoolean(key, value).apply();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public boolean getBooleanValue(String key, boolean defaultValue) {
|
|
43
|
+
return getPreferences().getBoolean(key, defaultValue);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Int
|
|
47
|
+
public void setIntValue(String key, int value) {
|
|
48
|
+
getPreferences().edit().putInt(key, value).apply();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public int getIntValue(String key, int defaultValue) {
|
|
52
|
+
return getPreferences().getInt(key, defaultValue);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Long
|
|
56
|
+
public void setLongValue(String key, long value) {
|
|
57
|
+
getPreferences().edit().putLong(key, value).apply();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public long getLongValue(String key, long defaultValue) {
|
|
61
|
+
return getPreferences().getLong(key, defaultValue);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// String
|
|
65
|
+
public void setStringValue(String key, String value) {
|
|
66
|
+
getPreferences().edit().putString(key, value).apply();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public String getStringValue(String key, String defaultValue) {
|
|
70
|
+
return getPreferences().getString(key, defaultValue);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public void clearAll() {
|
|
74
|
+
getPreferences().edit().clear().apply();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Note the caller is responsible for calling apply() or commit() on the
|
|
78
|
+
// returned SharedPreferences.Editor object for the remove to take affect
|
|
79
|
+
public SharedPreferences.Editor remove(String key) {
|
|
80
|
+
return getPreferences().edit().remove(key);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private SharedPreferences getPreferences() {
|
|
84
|
+
if (preferences == null) {
|
|
85
|
+
preferences =
|
|
86
|
+
ReactNativeFirebaseApp.getApplicationContext()
|
|
87
|
+
.getSharedPreferences(PREFERENCES_FILE, Context.MODE_PRIVATE);
|
|
88
|
+
}
|
|
89
|
+
return preferences;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
package io.invertase.firebase.app;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.content.Context;
|
|
21
|
+
import android.util.Log;
|
|
22
|
+
import com.google.firebase.FirebaseApp;
|
|
23
|
+
import com.google.firebase.FirebaseOptions;
|
|
24
|
+
|
|
25
|
+
public class ReactNativeFirebaseApp {
|
|
26
|
+
private static Context applicationContext;
|
|
27
|
+
|
|
28
|
+
public static Context getApplicationContext() {
|
|
29
|
+
return applicationContext;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static void setApplicationContext(Context applicationContext) {
|
|
33
|
+
Log.d("ReactNativeFirebaseApp", "received application context.");
|
|
34
|
+
ReactNativeFirebaseApp.applicationContext = applicationContext;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public static void initializeSecondaryApp(String name) {
|
|
38
|
+
FirebaseOptions options = FirebaseOptions.fromResource(applicationContext);
|
|
39
|
+
FirebaseApp.initializeApp(applicationContext, options, name);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public static void initializeSecondaryApp(String name, Context applicationContext) {
|
|
43
|
+
FirebaseOptions options = FirebaseOptions.fromResource(applicationContext);
|
|
44
|
+
FirebaseApp.initializeApp(applicationContext, options, name);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package io.invertase.firebase.app;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import io.invertase.firebase.common.ReactNativeFirebaseInitProvider;
|
|
21
|
+
|
|
22
|
+
public class ReactNativeFirebaseAppInitProvider extends ReactNativeFirebaseInitProvider {}
|