Skip to content

Commit b85a33f

Browse files
committed
Merge remote branch 'origin/master' into GitHub
2 parents e8aeb12 + 0841a2d commit b85a33f

File tree

104 files changed

+2203
-597
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2203
-597
lines changed

Android/firebase_dependencies.gradle

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ def firebaseDependenciesMap = [
2020
'admob' : ['com.google.firebase:firebase-ads:18.2.0',
2121
'com.google.android.gms:play-services-measurement-sdk-api:17.2.0'],
2222
'analytics' : ['com.google.firebase:firebase-analytics:17.2.0'],
23-
'auth' : ['com.google.firebase:firebase-auth:19.0.0'],
24-
'database' : ['com.google.firebase:firebase-database:19.1.0'],
23+
'auth' : ['com.google.firebase:firebase-auth:19.1.0'],
24+
'database' : ['com.google.firebase:firebase-database:19.2.0'],
2525
'dynamic_links' : ['com.google.firebase:firebase-dynamic-links:19.0.0'],
2626
'functions' : ['com.google.firebase:firebase-functions:19.0.1'],
2727
'instance_id' : ['com.google.firebase:firebase-iid:20.0.0'],
2828
'invites' : ['com.google.firebase:firebase-invites:17.0.0'],
2929
// Messaging has an additional local dependency to include.
3030
'messaging' : ['com.google.firebase:firebase-messaging:20.0.0',
3131
'firebase_cpp_sdk.messaging:messaging_java'],
32-
'performance' : ['com.google.firebase:firebase-perf:19.0.0'],
33-
'remote_config' : ['com.google.firebase:firebase-config:19.0.1'],
34-
'storage' : ['com.google.firebase:firebase-storage:19.0.1']
32+
'performance' : ['com.google.firebase:firebase-perf:19.0.1'],
33+
'remote_config' : ['com.google.firebase:firebase-config:19.0.3'],
34+
'storage' : ['com.google.firebase:firebase-storage:19.1.0']
3535
]
3636

3737
// A map of library to the gradle resources that they depend upon.

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ option(FIREBASE_CPP_BUILD_TESTS
4545
option(FIREBASE_FORCE_FAKE_SECURE_STORAGE
4646
"Disable use of platform secret store and use fake impl." OFF)
4747

48+
if(WIN32)
49+
# Turn on the use of the __cplusplus compiler define that is used to detect if
50+
# move operators are supported
51+
add_definitions("/Zc:__cplusplus")
52+
endif()
53+
4854
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR}/cmake)
4955
include(external_rules)
5056

README.md

+42-1
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,61 @@ git clone https://github.com/firebase/firebase-cpp-sdk.git
4949
## Prerequisites
5050
The following prerequisites are required for all platforms. Be sure to add any
5151
directories to your PATH as needed.
52+
5253
- [CMake](https://cmake.org/), version 3.1, or newer
53-
- [Python](https://www.python.com/), the latest version of 2.7, or newer
54+
- [Python2](https://www.python.com/), version of 2.7, or newer
5455
- [Abseil-py](https://github.com/abseil/abseil-py)
5556

57+
Note: Once python is installed you can use the following commands to install
58+
required packages:
59+
60+
* python -m ensurepip --default-pip
61+
* python -m pip install --user absl-py
62+
* python -m pip install --user protobuf
63+
5664
### Prerequisites for Desktop
5765
The following prerequisites are required when building the libraries for
5866
desktop platforms.
67+
5968
- [OpenSSL](https://www.openssl.org/), needed for Realtime Database
6069
- [Protobuf](https://github.com/protocolbuffers/protobuf/blob/master/src/README.md),
6170
needed for Remote Config
6271

72+
### Prerequisites for Windows
73+
Prebuilt packages for openssl can be found using google and if CMake fails to
74+
find the install path use the command line option
75+
**-DOPENSSL_ROOT_DIR=[Open SSL Dir]**.
76+
77+
Since there are no prebuilt packages for protobuf, getting it working on Windows
78+
is a little tricky. The following steps can be used as a guide:
79+
80+
* Download source [zip from github](https://github.com/protocolbuffers/protobuf/releases/download/v3.9.2/protobuf-all-3.9.2.zip).
81+
* Extract source and open command prompt to root folder
82+
* Make new folder **vsprojects**
83+
* CD to **vsprojects**
84+
* run cmake: **cmake ..\cmake -Dprotobuf_BUILD_TESTS=OFF -A Win32**
85+
* Build solution
86+
* Add command line define to firebase cmake command (see below)
87+
**-DPROTOBUF_SRC_ROOT_FOLDER=[Source Root Folder]**
88+
89+
Note: For x64 builds folder needs to be **vsprojects\x64** and change **Win32**
90+
in cmake command to **x64**
91+
92+
### Prerequisites for Mac
93+
Home brew can be used to install required dependencies:
94+
95+
```bash
96+
# https://github.com/protocolbuffers/protobuf/blob/master/kokoro/macos/prepare_build_macos_rc#L20
97+
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
98+
source $HOME/.rvm/scripts/rvm
99+
brew install cmake protobuf python2
100+
sudo chown -R $(whoami) /usr/local
101+
```
102+
63103
### Prerequisites for Android
64104
The following prerequisites are required when building the libraries for
65105
Android.
106+
66107
- Android SDK, Android NDK, and CMake for Android (version 3.10.2 recommended)
67108
- Download sdkmanager (either independently, or as a part of Android Studio)
68109
[here](https://developer.android.com/studio/#downloads)

admob/CMakeLists.txt

+16-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
cmake_minimum_required (VERSION 3.1)
1818
set (CMAKE_CXX_STANDARD 11)
1919

20+
include(binary_to_array)
2021
include(download_pod_headers)
22+
include(firebase_cpp_gradle)
2123

2224
project(firebase_admob NONE)
2325
enable_language(C)
@@ -36,6 +38,8 @@ set(common_SRCS
3638
src/common/rewarded_video_internal.cc)
3739

3840
# Define the resource build needed for Android
41+
firebase_cpp_gradle(":admob:admob_resources:generateDexJarRelease"
42+
"${CMAKE_CURRENT_LIST_DIR}/admob_resources/build/dexed.jar")
3943
binary_to_array("admob_resources"
4044
"${CMAKE_CURRENT_LIST_DIR}/admob_resources/build/dexed.jar"
4145
"firebase_admob"
@@ -107,7 +111,9 @@ else()
107111
add_definitions(-include assert.h -include string.h)
108112
endif()
109113

110-
if(IOS)
114+
if(ANDROID)
115+
firebase_cpp_proguard_file(admob)
116+
elseif(IOS)
111117
# AdMob for iOS uses weak references, which requires enabling Automatic
112118
# Reference Counting (ARC).
113119
set_property(
@@ -119,7 +125,7 @@ if(IOS)
119125
set(pod_target_name "download_admob_pod_headers")
120126
set(pods_dir "${PROJECT_BINARY_DIR}/Pods")
121127
set(pod_list "")
122-
list(APPEND pod_list "'Firebase/AdMob', '6.9.0'")
128+
list(APPEND pod_list "'Firebase/AdMob', '6.10.0'")
123129

124130
setup_pod_headers_target("${pod_target_name}" "${pods_dir}" "${pod_list}")
125131

@@ -129,6 +135,14 @@ if(IOS)
129135
PRIVATE
130136
${base_header_dir}/Google-Mobile-Ads-SDK
131137
)
138+
string(CONCAT google_mobile_ads_framework_path
139+
"${pods_dir}/Pods/Google-Mobile-Ads-SDK/"
140+
"Frameworks/GoogleMobileAdsFramework-Current/GoogleMobileAds.framework")
141+
# AdMob expects the header files to be in a subfolder, so set up a symlink to
142+
# accomplish that.
143+
symlink_framework_headers(firebase_admob ${pod_target_name}
144+
${google_mobile_ads_framework_path} GoogleMobileAds
145+
)
132146

133147
# Add a dependency to downloading the headers onto admob.
134148
add_dependencies(firebase_admob ${pod_target_name})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.google.FirebaseCppSdkBuild">
4+
<uses-permission android:name="android.permission.INTERNET"/>
5+
<uses-sdk android:minSdkVersion="3"/>
6+
</manifest>

admob/admob_resources/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ android {
3636

3737
sourceSets {
3838
main {
39-
manifest.srcFile '../../android_build_files/AndroidManifest.xml'
39+
manifest.srcFile 'AndroidManifest.xml'
4040
java {
4141
srcDirs = ['../src_java/com/google/firebase/admob/internal/cpp']
4242
}

analytics/CMakeLists.txt

+9-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ cmake_minimum_required (VERSION 3.1)
1818
set (CMAKE_CXX_STANDARD 11)
1919

2020
include(download_pod_headers)
21+
include(firebase_cpp_gradle)
2122

2223
project(firebase_analytics NONE)
2324
enable_language(C)
@@ -121,7 +122,9 @@ else()
121122
add_definitions(-include assert.h -include string.h)
122123
endif()
123124

124-
if(IOS)
125+
if(ANDROID)
126+
firebase_cpp_proguard_file(analytics)
127+
elseif(IOS)
125128
# Enable Automatic Reference Counting (ARC).
126129
set_property(
127130
TARGET firebase_analytics
@@ -132,17 +135,19 @@ if(IOS)
132135
set(pod_target_name "download_analytics_pod_headers")
133136
set(pods_dir "${PROJECT_BINARY_DIR}/Pods")
134137
set(pod_list "")
135-
list(APPEND pod_list "'Firebase/Core', '6.9.0'")
136-
list(APPEND pod_list "'Firebase/Analytics', '6.9.0'")
138+
list(APPEND pod_list "'Firebase/Core', '6.10.0'")
139+
list(APPEND pod_list "'Firebase/Analytics', '6.10.0'")
137140

138141
setup_pod_headers_target("${pod_target_name}" "${pods_dir}" "${pod_list}")
139142

140143
# Add the Cocoapod headers to the include directories
141144
set(base_header_dir "${pods_dir}/Pods/Headers/Public")
145+
set(analytics_framework_path
146+
"${pods_dir}/Pods/FirebaseAnalytics/Frameworks/FirebaseAnalytics.framework")
142147
target_include_directories(firebase_analytics
143148
PRIVATE
144149
${base_header_dir}/FirebaseCore
145-
${base_header_dir}/FirebaseAnalytics/FirebaseAnalytics
150+
${analytics_framework_path}/Headers
146151
)
147152

148153
# Add a dependency to downloading the headers onto analytics.

analytics/src/analytics_android.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ Future<std::string> GetAnalyticsInstanceId() {
397397
util::RegisterCallbackOnTask(
398398
env, task,
399399
[](JNIEnv* env, jobject result, util::FutureResult result_code,
400-
int status, const char* status_message, void* callback_data) {
400+
const char* status_message, void* callback_data) {
401401
auto* future_data = internal::FutureData::Get();
402402
if (future_data) {
403403
bool success =

analytics/src/analytics_ios.mm

+109-4
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,103 @@
2424
#include "app/src/include/firebase/version.h"
2525
#include "app/src/assert.h"
2626
#include "app/src/log.h"
27+
#include "app/src/mutex.h"
28+
#include "app/src/time.h"
29+
#include "app/src/thread.h"
30+
#include "app/src/util.h"
2731
#include "app/src/util_ios.h"
2832

2933
namespace firebase {
3034
namespace analytics {
3135

36+
// Used to workaround b/143656277 and b/110166640
37+
class AnalyticsDataResetter {
38+
private:
39+
enum ResetState {
40+
kResetStateNone = 0,
41+
kResetStateRequested,
42+
kResetStateRetry,
43+
};
44+
public:
45+
// Initialize the class.
46+
AnalyticsDataResetter() : reset_state_(kResetStateNone), reset_timestamp_(0) {}
47+
48+
// Reset analytics data.
49+
void Reset() {
50+
MutexLock lock(mutex_);
51+
reset_timestamp_ = firebase::internal::GetTimestampEpoch();
52+
reset_state_ = kResetStateRequested;
53+
instance_id_ = util::StringFromNSString([FIRAnalytics appInstanceID]);
54+
[FIRAnalytics resetAnalyticsData];
55+
}
56+
57+
// Get the instance ID, returning a non-empty string if it's valid or an empty string if it's
58+
// still being reset.
59+
std::string GetInstanceId() {
60+
MutexLock lock(mutex_);
61+
std::string current_instance_id = util::StringFromNSString([FIRAnalytics appInstanceID]);
62+
uint64_t reset_time_elapsed_milliseconds = GetResetTimeElapsedMilliseconds();
63+
switch (reset_state_) {
64+
case kResetStateNone:
65+
break;
66+
case kResetStateRequested:
67+
if (reset_time_elapsed_milliseconds >= kResetRetryIntervalMilliseconds) {
68+
// Firebase Analytics on iOS can take a while to initialize, in this case we try to reset
69+
// again if the instance ID hasn't changed for a while.
70+
reset_state_ = kResetStateRetry;
71+
reset_timestamp_ = firebase::internal::GetTimestampEpoch();
72+
[FIRAnalytics resetAnalyticsData];
73+
return std::string();
74+
}
75+
FIREBASE_CASE_FALLTHROUGH;
76+
77+
case kResetStateRetry:
78+
if ((current_instance_id.empty() || current_instance_id == instance_id_) &&
79+
reset_time_elapsed_milliseconds < kResetTimeoutMilliseconds) {
80+
return std::string();
81+
}
82+
break;
83+
}
84+
instance_id_ = current_instance_id;
85+
return current_instance_id;
86+
}
87+
88+
private:
89+
// Get the time elapsed in milliseconds since reset was requested.
90+
uint64_t GetResetTimeElapsedMilliseconds() const {
91+
return firebase::internal::GetTimestampEpoch() - reset_timestamp_;
92+
}
93+
94+
private:
95+
Mutex mutex_;
96+
// Reset attempt.
97+
ResetState reset_state_;
98+
// When a reset was last requested.
99+
uint64_t reset_timestamp_;
100+
// Instance ID before it was reset.
101+
std::string instance_id_;
102+
103+
// Time to wait before trying to reset again.
104+
static const uint64_t kResetRetryIntervalMilliseconds;
105+
// Time to wait before giving up on resetting the ID.
106+
static const uint64_t kResetTimeoutMilliseconds;
107+
};
108+
32109
DEFINE_FIREBASE_VERSION_STRING(FirebaseAnalytics);
33110

111+
const uint64_t AnalyticsDataResetter::kResetRetryIntervalMilliseconds = 1000;
112+
const uint64_t AnalyticsDataResetter::kResetTimeoutMilliseconds = 5000;
113+
34114
static const double kMillisecondsPerSecond = 1000.0;
115+
static Mutex g_mutex; // NOLINT
35116
static bool g_initialized = false;
117+
static AnalyticsDataResetter *g_resetter = nullptr;
36118

37119
// Initialize the API.
38120
void Initialize(const ::firebase::App& app) {
121+
MutexLock lock(g_mutex);
39122
g_initialized = true;
123+
g_resetter = new AnalyticsDataResetter();
40124
internal::RegisterTerminateOnDefaultAppDestroy();
41125
internal::FutureData::Create();
42126
}
@@ -50,8 +134,11 @@ void Initialize(const ::firebase::App& app) {
50134

51135
// Terminate the API.
52136
void Terminate() {
137+
MutexLock lock(g_mutex);
53138
internal::FutureData::Destroy();
54139
internal::UnregisterTerminateOnDefaultAppDestroy();
140+
delete g_resetter;
141+
g_resetter = nullptr;
55142
g_initialized = false;
56143
}
57144

@@ -169,22 +256,40 @@ void SetCurrentScreen(const char* screen_name, const char* screen_class) {
169256
}
170257

171258
void ResetAnalyticsData() {
259+
MutexLock lock(g_mutex);
172260
FIREBASE_ASSERT_RETURN_VOID(internal::IsInitialized());
173-
[FIRAnalytics resetAnalyticsData];
261+
g_resetter->Reset();
174262
}
175263

176264
Future<std::string> GetAnalyticsInstanceId() {
265+
MutexLock lock(g_mutex);
177266
FIREBASE_ASSERT_RETURN(Future<std::string>(), internal::IsInitialized());
178267
auto* api = internal::FutureData::Get()->api();
179268
const auto future_handle = api->SafeAlloc<std::string>(
180269
internal::kAnalyticsFnGetAnalyticsInstanceId);
181-
api->CompleteWithResult(
182-
future_handle, 0, "",
183-
util::StringFromNSString([FIRAnalytics appInstanceID]));
270+
static int kPollTimeMs = 100;
271+
Thread get_id_thread([](SafeFutureHandle<std::string>* handle) {
272+
for ( ; ; ) {
273+
{
274+
MutexLock lock(g_mutex);
275+
if (!internal::IsInitialized()) break;
276+
std::string instance_id = g_resetter->GetInstanceId();
277+
if (!instance_id.empty()) {
278+
internal::FutureData::Get()->api()->CompleteWithResult(
279+
*handle, 0, "", instance_id);
280+
break;
281+
}
282+
}
283+
firebase::internal::Sleep(kPollTimeMs);
284+
}
285+
delete handle;
286+
}, new SafeFutureHandle<std::string>(future_handle));
287+
get_id_thread.Detach();
184288
return Future<std::string>(api, future_handle.get());
185289
}
186290

187291
Future<std::string> GetAnalyticsInstanceIdLastResult() {
292+
MutexLock lock(g_mutex);
188293
FIREBASE_ASSERT_RETURN(Future<std::string>(), internal::IsInitialized());
189294
return static_cast<const Future<std::string>&>(
190295
internal::FutureData::Get()->api()->LastResult(

0 commit comments

Comments
 (0)