Skip to content

Commit 93388a9

Browse files
committed
Integrate Latest @ 128857522
- Implement Google Play services checker in sample apps. - Updated sample project gradle dependencies to 9.4.0 and added play-services-base dependency. - Make the sample apps able to handle orientation changes without restarting. CL: 128857522
1 parent 50e7316 commit 93388a9

File tree

17 files changed

+227
-95
lines changed

17 files changed

+227
-95
lines changed

admob/testapp/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
1010
<application android:label="@string/app_name">
1111
<activity android:name="android.app.NativeActivity"
12-
android:screenOrientation="portrait">
12+
android:screenOrientation="portrait"
13+
android:configChanges="orientation|screenSize">
1314
<meta-data android:name="android.app.lib_name"
1415
android:value="android_main" />
1516
<intent-filter>

admob/testapp/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ android {
8989

9090
dependencies {
9191
compile fileTree(dir: 'libs', include: ['*.jar'])
92-
compile 'com.google.android.gms:play-services-ads:9.0.2'
92+
compile 'com.google.firebase:firebase-ads:9.4.0'
93+
compile 'com.google.android.gms:play-services-base:9.4.0'
9394
}
9495

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

admob/testapp/src/common_main.cc

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ class LoggingBannerViewListener : public firebase::admob::BannerView::Listener {
2828
LoggingBannerViewListener() {}
2929
void OnPresentationStateChanged(
3030
firebase::admob::BannerView* banner_view,
31-
firebase::admob::BannerView::PresentationState new_state) {
31+
firebase::admob::BannerView::PresentationState new_state) override {
3232
::LogMessage("BannerView PresentationState has changed to %d.", new_state);
3333
}
34-
3534
void OnBoundingBoxChanged(firebase::admob::BannerView* banner_view,
36-
firebase::admob::BoundingBox new_box) {
35+
firebase::admob::BoundingBox new_box) override {
3736
::LogMessage(
3837
"BannerView BoundingBox has changed to (x: %d, y: %d, width: %d, "
3938
"height %d).",
@@ -48,7 +47,7 @@ class LoggingInterstitialAdListener
4847
LoggingInterstitialAdListener() {}
4948
void OnPresentationStateChanged(
5049
firebase::admob::InterstitialAd* interstitial_ad,
51-
firebase::admob::InterstitialAd::PresentationState new_state) {
50+
firebase::admob::InterstitialAd::PresentationState new_state) override {
5251
::LogMessage("InterstitialAd PresentationState has changed to %d.",
5352
new_state);
5453
}
@@ -81,44 +80,36 @@ static const int kBirthdayYear = 1976;
8180

8281
static void WaitForFutureCompletion(firebase::FutureBase future) {
8382
while (!ProcessEvents(1000)) {
84-
if (future.Status() != ::firebase::kFutureStatusPending) {
83+
if (future.Status() != firebase::kFutureStatusPending) {
8584
break;
8685
}
8786
}
8887

89-
if (future.Error() != ::firebase::admob::kAdMobErrorNone) {
88+
if (future.Error() != firebase::admob::kAdMobErrorNone) {
9089
LogMessage("Action failed with error code %d and message \"%s\".",
9190
future.Error(), future.ErrorMessage());
9291
}
9392
}
9493

9594
// Execute all methods of the C++ admob API.
9695
extern "C" int common_main(int argc, const char* argv[]) {
97-
namespace admob = ::firebase::admob;
98-
::firebase::App* app;
96+
firebase::App* app;
9997
LogMessage("Initializing the AdMob library.");
100-
do {
98+
10199
#if defined(__ANDROID__)
102-
app = ::firebase::App::Create(::firebase::AppOptions(), GetJniEnv(),
103-
GetActivity());
100+
app =
101+
firebase::App::Create(firebase::AppOptions(), GetJniEnv(), GetActivity());
104102
#else
105-
app = ::firebase::App::Create(::firebase::AppOptions());
103+
app = firebase::App::Create(firebase::AppOptions());
106104
#endif // defined(__ANDROID__)
107105

108-
if (app == nullptr) {
109-
LogMessage("Couldn't create firebase app, try again.");
110-
// Wait a few moments, and try to create app again.
111-
ProcessEvents(1000);
112-
}
113-
} while (app == nullptr);
114-
115106
LogMessage("Created the Firebase App %x.",
116107
static_cast<int>(reinterpret_cast<intptr_t>(app)));
117108

118109
LogMessage("Initializing the AdMob with Firebase API.");
119-
admob::Initialize(*app);
110+
firebase::admob::Initialize(*app);
120111

121-
::firebase::admob::AdRequest request;
112+
firebase::admob::AdRequest request;
122113
// If the app is aware of the user's gender, it can be added to the targeting
123114
// information. Otherwise, "unknown" should be used.
124115
request.gender = firebase::admob::kGenderUnknown;
@@ -141,7 +132,7 @@ extern "C" int common_main(int argc, const char* argv[]) {
141132

142133
// "Extra" key value pairs can be added to the request as well. Typically
143134
// these are used when testing new features.
144-
static const ::firebase::admob::KeyValuePair kRequestExtras[] = {
135+
static const firebase::admob::KeyValuePair kRequestExtras[] = {
145136
{"the_name_of_an_extra", "the_value_for_that_extra"}};
146137
request.extras_count = sizeof(kRequestExtras) / sizeof(kRequestExtras[0]);
147138
request.extras = kRequestExtras;
@@ -155,18 +146,18 @@ extern "C" int common_main(int argc, const char* argv[]) {
155146
// Device IDs can be obtained by checking the logcat or the Xcode log while
156147
// debugging. They appear as a long string of hex characters.
157148
request.test_device_id_count =
158-
sizeof(kTestDeviceIDs) / sizeof(kTestDeviceIDs);
149+
sizeof(kTestDeviceIDs) / sizeof(kTestDeviceIDs[0]);
159150
request.test_device_ids = kTestDeviceIDs;
160151

161152
// Create an ad size for the BannerView.
162-
admob::AdSize ad_size;
163-
ad_size.ad_size_type = admob::kAdSizeStandard;
153+
firebase::admob::AdSize ad_size;
154+
ad_size.ad_size_type = firebase::admob::kAdSizeStandard;
164155
ad_size.width = kBannerWidth;
165156
ad_size.height = kBannerHeight;
166157

167158
LogMessage("Creating the BannerView.");
168159
LoggingBannerViewListener banner_listener;
169-
::firebase::admob::BannerView* banner = new admob::BannerView();
160+
firebase::admob::BannerView* banner = new firebase::admob::BannerView();
170161
banner->SetListener(&banner_listener);
171162
banner->Initialize(GetWindowContext(), kBannerAdUnit, ad_size);
172163

@@ -186,32 +177,32 @@ extern "C" int common_main(int argc, const char* argv[]) {
186177

187178
// Move to each of the six pre-defined positions.
188179
LogMessage("Moving the banner ad to top-center.");
189-
banner->MoveTo(admob::BannerView::kPositionTop);
180+
banner->MoveTo(firebase::admob::BannerView::kPositionTop);
190181

191182
WaitForFutureCompletion(banner->MoveToLastResult());
192183

193184
LogMessage("Moving the banner ad to top-left.");
194-
banner->MoveTo(admob::BannerView::kPositionTopLeft);
185+
banner->MoveTo(firebase::admob::BannerView::kPositionTopLeft);
195186

196187
WaitForFutureCompletion(banner->MoveToLastResult());
197188

198189
LogMessage("Moving the banner ad to top-right.");
199-
banner->MoveTo(admob::BannerView::kPositionTopRight);
190+
banner->MoveTo(firebase::admob::BannerView::kPositionTopRight);
200191

201192
WaitForFutureCompletion(banner->MoveToLastResult());
202193

203194
LogMessage("Moving the banner ad to bottom-center.");
204-
banner->MoveTo(admob::BannerView::kPositionBottom);
195+
banner->MoveTo(firebase::admob::BannerView::kPositionBottom);
205196

206197
WaitForFutureCompletion(banner->MoveToLastResult());
207198

208199
LogMessage("Moving the banner ad to bottom-left.");
209-
banner->MoveTo(admob::BannerView::kPositionBottomLeft);
200+
banner->MoveTo(firebase::admob::BannerView::kPositionBottomLeft);
210201

211202
WaitForFutureCompletion(banner->MoveToLastResult());
212203

213204
LogMessage("Moving the banner ad to bottom-right.");
214-
banner->MoveTo(admob::BannerView::kPositionBottomRight);
205+
banner->MoveTo(firebase::admob::BannerView::kPositionBottomRight);
215206

216207
WaitForFutureCompletion(banner->MoveToLastResult());
217208

@@ -248,10 +239,16 @@ extern "C" int common_main(int argc, const char* argv[]) {
248239

249240
WaitForFutureCompletion(banner->MoveToLastResult());
250241

242+
LogMessage("Hiding the banner ad now that we're done with it.");
243+
banner->Hide();
244+
245+
WaitForFutureCompletion(banner->HideLastResult());
246+
251247
// Create and test InterstitialAd.
252248
LogMessage("Creating the InterstitialAd.");
253249
LoggingInterstitialAdListener interstitial_listener;
254-
::firebase::admob::InterstitialAd* interstitial = new admob::InterstitialAd();
250+
firebase::admob::InterstitialAd* interstitial =
251+
new firebase::admob::InterstitialAd();
255252
interstitial->SetListener(&interstitial_listener);
256253
interstitial->Initialize(GetWindowContext(), kInterstitialAdUnit);
257254

@@ -267,13 +264,24 @@ extern "C" int common_main(int argc, const char* argv[]) {
267264
LogMessage("Showing the interstitial ad.");
268265
interstitial->Show();
269266

267+
WaitForFutureCompletion(interstitial->ShowLastResult());
268+
269+
// Wait for the user to close the interstitial.
270+
while (interstitial->GetPresentationState() !=
271+
firebase::admob::InterstitialAd::PresentationState::
272+
kPresentationStateHidden) {
273+
ProcessEvents(1000);
274+
}
275+
276+
LogMessage("Done!");
277+
270278
// Wait until the user kills the app.
271279
while (!ProcessEvents(1000)) {
272280
}
273281

274-
delete interstitial;
275282
delete banner;
276-
admob::Terminate();
283+
delete interstitial;
284+
firebase::admob::Terminate();
277285
delete app;
278286

279287
return 0;

analytics/testapp/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
<uses-permission android:name="android.permission.WAKE_LOCK" />
99
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
1010
<application android:label="@string/app_name">
11-
<activity android:name="android.app.NativeActivity">
11+
<activity android:name="android.app.NativeActivity"
12+
android:screenOrientation="portrait"
13+
android:configChanges="orientation|screenSize">
1214
<meta-data android:name="android.app.lib_name"
1315
android:value="android_main" />
1416
<intent-filter>

analytics/testapp/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ android {
9090

9191
dependencies {
9292
compile fileTree(dir: 'libs', include: ['*.jar'])
93-
compile 'com.google.firebase:firebase-analytics:9.0.2'
93+
compile 'com.google.firebase:firebase-analytics:9.4.0'
94+
compile 'com.google.android.gms:play-services-base:9.4.0'
9495
}
9596

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

auth/testapp/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
1010
<application android:label="@string/app_name">
1111
<activity android:name="android.app.NativeActivity"
12-
android:screenOrientation="portrait">
12+
android:screenOrientation="portrait"
13+
android:configChanges="orientation|screenSize">
1314
<meta-data android:name="android.app.lib_name"
1415
android:value="android_main" />
1516
<intent-filter>

auth/testapp/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ android {
9090

9191
dependencies {
9292
compile fileTree(dir: 'libs', include: ['*.jar'])
93-
compile 'com.google.firebase:firebase-auth:9.0.2'
94-
93+
compile 'com.google.firebase:firebase-auth:9.4.0'
94+
compile 'com.google.android.gms:play-services-base:9.4.0'
9595
}
9696

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

auth/testapp/src/common_main.cc

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "firebase/app.h"
2121
#include "firebase/auth.h"
22+
#include "google_play_services/availability.h"
2223

2324
// Thin OS abstraction layer.
2425
#include "main.h" // NOLINT
@@ -219,25 +220,52 @@ class UserLogin {
219220
extern "C" int common_main(int argc, const char* argv[]) {
220221
App* app;
221222
LogMessage("Starting Auth tests.");
222-
do {
223-
// Create the App wrapper.
223+
// Create the App wrapper.
224+
224225
#if defined(__ANDROID__)
225-
app = App::Create(AppOptions(), GetJniEnv(), GetActivity());
226+
app = App::Create(AppOptions(), GetJniEnv(), GetActivity());
226227
#else
227-
app = App::Create(AppOptions());
228+
app = App::Create(AppOptions());
228229
#endif // defined(__ANDROID__)
229230

230-
if (app == nullptr) {
231-
LogMessage("Couldn't create firebase app, try again.");
232-
// Wait a few moments, and try to create app again.
233-
ProcessEvents(1000);
234-
}
235-
} while (app == nullptr);
236-
237231
LogMessage("Created the Firebase app %x.",
238232
static_cast<int>(reinterpret_cast<intptr_t>(app)));
239233
// Create the Auth class for that App.
240-
Auth* auth = Auth::GetAuth(app);
234+
::firebase::InitResult init_result;
235+
bool try_again;
236+
Auth* auth;
237+
do {
238+
try_again = false;
239+
auth = Auth::GetAuth(app, &init_result);
240+
241+
#if defined(__ANDROID__)
242+
// On Android, we need to update or activate Google Play services
243+
// before we can initialize this Firebase module.
244+
if (init_result == firebase::kInitResultFailedMissingDependency) {
245+
LogMessage("Google Play services unavailable, trying to fix.");
246+
firebase::Future<void> make_available =
247+
google_play_services::MakeAvailable(app->GetJNIEnv(),
248+
app->activity());
249+
while (make_available.Status() != ::firebase::kFutureStatusComplete) {
250+
if (ProcessEvents(100)) return 1; // Return if exit was triggered.
251+
}
252+
253+
if (make_available.Error() == 0) {
254+
LogMessage("Google Play services now available, continuing.");
255+
try_again = true;
256+
} else {
257+
LogMessage("Google Play services still unavailable.");
258+
}
259+
}
260+
#endif // defined(__ANDROID__)
261+
} while (try_again);
262+
263+
if (init_result != firebase::kInitResultSuccess) {
264+
LogMessage("Failed to initialize Auth, exiting.");
265+
ProcessEvents(2000);
266+
return 1;
267+
}
268+
241269
LogMessage("Created the Auth %x class for the Firebase app.",
242270
static_cast<int>(reinterpret_cast<intptr_t>(auth)));
243271

invites/testapp/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
<uses-permission android:name="android.permission.INTERNET" />
77
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
88
<application android:label="@string/app_name">
9-
<activity android:name="android.app.NativeActivity">
9+
<activity android:name="android.app.NativeActivity"
10+
android:screenOrientation="portrait"
11+
android:configChanges="orientation|screenSize">
1012
<meta-data android:name="android.app.lib_name"
1113
android:value="android_main" />
1214
<intent-filter>

invites/testapp/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ android {
9090

9191
dependencies {
9292
compile fileTree(dir: 'libs', include: ['*.jar'])
93-
compile 'com.google.firebase:firebase-invites:9.0.2'
93+
compile 'com.google.firebase:firebase-invites:9.4.0'
94+
compile 'com.google.android.gms:play-services-base:9.4.0'
9495
}
9596

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

0 commit comments

Comments
 (0)