Skip to content

Commit 2b89229

Browse files
author
Stewart Miles
committed
Integrate Latest @ 122440465
Changes to admob/testapp ... - Fixed clean up of Banner View and Interstitial Ad helper classes. - Updates testapp/build.gradle files to use current tools. Fixes several broken gradle builds. - Adds a LaunchScreen storyboard to the AdMob testapp to remvove black bars on top and bottom of simulator. - Fix old podfile versions in Auth, Admob, RemoteConfig - Cleans up log messages in AdMob testapp common_main.cc. - Adding logging output window to admob testapp. Includes both ios and android. - Use console.firebase.google.com instead of g.co/firebase Changes to analytics/testapp ... - Integrated desktop_main.cc changes to all test applications. - Updates testapp/build.gradle files to use current tools. Fixes several broken gradle builds. - Added storyboard to Analytics test app missing from cl/122311484 - Clean up before shutting down the Analytics test application. - Migrate changes from admob testapp to other testapps. - Removed duplicated title string from test applications. - Updated Analytics testapp dependencies to latest Pods and aars. - Mirror logging changes from admob across all samples. Changes to auth/testapp ... - Integrated desktop_main.cc changes to all test applications. - Auth test application shutdown. - Added desktop test application for each API. - Updates testapp/build.gradle files to use current tools. Fixes several broken gradle builds. - Removed TODOs and temporary code, and filed bugs for them. - Fix old podfile versions in Auth, Admob, RemoteConfig - Migrate changes from admob testapp to other testapps. - Removed duplicated title string from test applications. - Add Twitter and GitHub credential support. - Change all API interfaces to return Future rather than const Future&. - Put auth under firebase::auth namespace, instead of just firebase. - Mirror logging changes from admob across all samples. Changes to invites/testapp ... - Remove ios_main.h from Invites xcode project. - Integrated desktop_main.cc changes to all test applications. - Clean up before shutting down the Invites test application. - Added desktop test application for each API. - Updates testapp/build.gradle files to use current tools. Fixes several broken gradle builds. - Migrate changes from admob testapp to other testapps. - Removed duplicated title string from test applications. - Fix iOS build dependencies (Podfile) for Invites. - Updated build.gradle to match the dependencies that Invites quickstart uses for M8. - Mirror logging changes from admob across all samples. Changes to messaging/testapp ... - Integrated desktop_main.cc changes to all test applications. - Added desktop test application for each API. - Updates testapp/build.gradle files to use current tools. Fixes several broken gradle builds. - Updated the sample app to work around the known issue where the app does notrespond to data/notification messages when in the background. - Fixed re-initialization of the Firebase Messaging test application. - Migrate changes from admob testapp to other testapps. - Fixed notification of instance IDs in the messaging test application. - Removed "Main tick" message from messaging test application. - Removed duplicated title string from test applications. - Updating iOS Messaging to M8. This is a breaking change for the release config. - Mirror logging changes from admob across all samples. Changes to remote_config/testapp ... - Integrated desktop_main.cc changes to all test applications. - Added desktop test application for each API. - Updates testapp/build.gradle files to use current tools. Fixes several broken gradle builds. - Clean up before shutting down the Remote Config test application. - Fix old podfile versions in Auth, Admob, RemoteConfig - Migrate changes from admob testapp to other testapps. - Removed duplicated title string from test applications. - Remove the asserts for default values in the Remote Config testapp. - Update the Remote Config podfile and build.gradle - Change Remote Config's SetDefault use of map to an array of typedef pair. CL: 122440465
1 parent 7891f1e commit 2b89229

File tree

88 files changed

+2520
-1295
lines changed

Some content is hidden

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

88 files changed

+2520
-1295
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
3+
<dependencies>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
5+
</dependencies>
6+
<scenes/>
7+
</document>

admob/testapp/Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ source 'https://github.com/CocoaPods/Specs.git'
33
platform :ios, '7.0'
44
# AdMob test application.
55
target 'testapp' do
6-
pod 'Firebase/Core', '3.1.1'
7-
pod 'Google-Mobile-Ads-SDK', '~> 7.7
6+
pod 'Firebase/AdMob'
7+
pod 'Firebase/Core', '3.1.6'
88
end

admob/testapp/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:1.5.0'
9-
classpath 'com.google.gms:google-services:1.5.1-beta2'
8+
classpath 'com.android.tools.build:gradle:2.0.0'
9+
classpath 'com.google.gms:google-services:3.0.0'
1010
}
1111
}
1212

@@ -59,7 +59,7 @@ project.ext {
5959

6060
android {
6161
compileSdkVersion 23
62-
buildToolsVersion '23.0.1'
62+
buildToolsVersion '23.0.2'
6363

6464
sourceSets {
6565
main {
@@ -89,7 +89,7 @@ android {
8989

9090
dependencies {
9191
compile fileTree(dir: 'libs', include: ['*.jar'])
92-
compile 'com.google.android.gms:play-services-ads:8.5.4'
92+
compile 'com.google.android.gms:play-services-ads:9.0.0'
9393
}
9494

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

admob/testapp/readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Getting Started
3434
- For further details please refer to the
3535
[general instructions for setting up an iOS app with Firebase](https://developers.google.com/firebase/docs/ios/setup).
3636
- Register your iOS app with Firebase.
37-
- Create a new app on [Firebase console](https://g.co/firebase), and attach
37+
- Create a new app on the [Firebase console](https://console.firebase.google.com), and attach
3838
your iOS app to it.
3939
- You can use "com.google.ios.admob.testapp" as the iOS Bundle ID
4040
while you're testing. You can omit App Store ID while testing.
@@ -44,7 +44,7 @@ Getting Started
4444
- You will need to either,
4545
1. Check "Copy items if needed" when adding the frameworks, or
4646
2. Add the framework path in "Framework Search Paths"
47-
- e.g. If you downloaded the Firebase C++ SDK to
47+
- For example, if you downloaded the Firebase C++ SDK to
4848
`/Users/me/firebase_cpp_sdk`,
4949
then you would add the path
5050
`/Users/me/firebase_cpp_sdk/frameworks/ios/universal`.
@@ -61,7 +61,7 @@ Getting Started
6161
6262
### Android
6363
- Register your Android app with Firebase.
64-
- Create a new app on [Firebase console](https://g.co/firebase), and attach
64+
- Create a new app on the [Firebase console](https://console.firebase.google.com), and attach
6565
your Android app to it.
6666
- You can use "com.google.android.admob.testapp" as the Package Name
6767
while you're testing.

admob/testapp/src/android/android_main.cc

Lines changed: 203 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,60 +13,243 @@
1313
// limitations under the License.
1414

1515
#include <stdarg.h>
16+
#include <stdio.h>
1617

1718
#include <android/log.h>
1819
#include <android_native_app_glue.h>
20+
#include <pthread.h>
21+
#include <cassert>
1922

2023
#include "main.h" // NOLINT
2124

2225
// This implementation is derived from http://github.com/google/fplutil
2326

24-
extern "C" int common_main(void* ad_parent);
27+
extern "C" int common_main(int argc, const char* argv[]);
2528

26-
static struct android_app* gAppState = nullptr;
29+
static struct android_app* g_app_state = nullptr;
30+
static bool g_destroy_requested = false;
31+
static bool g_started = false;
32+
static bool g_restarted = false;
33+
static pthread_mutex_t g_started_mutex;
34+
35+
// Handle state changes from via native app glue.
36+
static void OnAppCmd(struct android_app* app, int32_t cmd) {
37+
g_destroy_requested |= cmd == APP_CMD_DESTROY;
38+
}
2739

2840
// Process events pending on the main thread.
29-
bool ProcessAndroidEvents(int msec) {
41+
// Returns true when the app receives an event requesting exit.
42+
bool ProcessEvents(int msec) {
3043
struct android_poll_source* source = nullptr;
3144
int events;
3245
int looperId = ALooper_pollAll(msec, nullptr, &events,
3346
reinterpret_cast<void**>(&source));
3447
if (looperId >= 0 && source) {
35-
source->process(gAppState, source);
48+
source->process(g_app_state, source);
49+
}
50+
return g_destroy_requested | g_restarted;
51+
}
52+
53+
// Get the activity.
54+
jobject GetActivity() { return g_app_state->activity->clazz; }
55+
56+
// Get the window context. For Android, it's a jobject pointing to the Activity.
57+
jobject GetWindowContext() { return g_app_state->activity->clazz; }
58+
59+
// Find a class, attempting to load the class if it's not found.
60+
jclass FindClass(JNIEnv* env, jobject activity_object, const char* class_name) {
61+
jclass class_object = env->FindClass(class_name);
62+
if (env->ExceptionCheck()) {
63+
env->ExceptionClear();
64+
// If the class isn't found it's possible NativeActivity is being used by
65+
// the application which means the class path is set to only load system
66+
// classes. The following falls back to loading the class using the
67+
// Activity before retrieving a reference to it.
68+
jclass activity_class = env->FindClass("android/app/Activity");
69+
jmethodID activity_get_class_loader = env->GetMethodID(
70+
activity_class, "getClassLoader", "()Ljava/lang/ClassLoader;");
71+
72+
jobject class_loader_object =
73+
env->CallObjectMethod(activity_object, activity_get_class_loader);
74+
75+
jclass class_loader_class = env->FindClass("java/lang/ClassLoader");
76+
jmethodID class_loader_load_class =
77+
env->GetMethodID(class_loader_class, "loadClass",
78+
"(Ljava/lang/String;)Ljava/lang/Class;");
79+
jstring class_name_object = env->NewStringUTF(class_name);
80+
81+
class_object = static_cast<jclass>(env->CallObjectMethod(
82+
class_loader_object, class_loader_load_class, class_name_object));
83+
84+
if (env->ExceptionCheck()) {
85+
env->ExceptionClear();
86+
class_object = nullptr;
87+
}
88+
env->DeleteLocalRef(class_name_object);
89+
env->DeleteLocalRef(class_loader_object);
90+
}
91+
return class_object;
92+
}
93+
94+
// Vars that we need available for appending text to the log window:
95+
class LoggingUtilsData {
96+
public:
97+
LoggingUtilsData()
98+
: logging_utils_class_(nullptr),
99+
logging_utils_add_log_text_(0),
100+
logging_utils_init_log_window_(0) {}
101+
102+
~LoggingUtilsData() {
103+
JNIEnv* env = GetJniEnv();
104+
assert(env);
105+
if (logging_utils_class_) {
106+
env->DeleteGlobalRef(logging_utils_class_);
107+
}
108+
}
109+
110+
void Init() {
111+
JNIEnv* env = GetJniEnv();
112+
assert(env);
113+
114+
jclass logging_utils_class = FindClass(
115+
env, GetActivity(), "com/google/firebase/example/LoggingUtils");
116+
assert(logging_utils_class != 0);
117+
118+
// Need to store as global references so it don't get moved during garbage
119+
// collection.
120+
logging_utils_class_ =
121+
static_cast<jclass>(env->NewGlobalRef(logging_utils_class));
122+
env->DeleteLocalRef(logging_utils_class);
123+
124+
logging_utils_init_log_window_ = env->GetStaticMethodID(
125+
logging_utils_class_, "initLogWindow", "(Landroid/app/Activity;)V");
126+
logging_utils_add_log_text_ = env->GetStaticMethodID(
127+
logging_utils_class_, "addLogText", "(Ljava/lang/String;)V");
128+
129+
env->CallStaticVoidMethod(logging_utils_class_,
130+
logging_utils_init_log_window_, GetActivity());
131+
}
132+
133+
void AppendText(const char* text) {
134+
if (logging_utils_class_ == 0) return; // haven't been initted yet
135+
JNIEnv* env = GetJniEnv();
136+
assert(env);
137+
jstring text_string = env->NewStringUTF(text);
138+
env->CallStaticVoidMethod(logging_utils_class_, logging_utils_add_log_text_,
139+
text_string);
140+
env->DeleteLocalRef(text_string);
141+
}
142+
143+
private:
144+
jclass logging_utils_class_;
145+
jmethodID logging_utils_add_log_text_;
146+
jmethodID logging_utils_init_log_window_;
147+
};
148+
149+
LoggingUtilsData* g_logging_utils_data;
150+
151+
// Checks if a JNI exception has happened, and if so, logs it to the console.
152+
void CheckJNIException() {
153+
JNIEnv* env = GetJniEnv();
154+
if (env->ExceptionCheck()) {
155+
// Get the exception text.
156+
jthrowable exception = env->ExceptionOccurred();
157+
env->ExceptionClear();
158+
159+
// Convert the exception to a string.
160+
jclass object_class = env->FindClass("java/lang/Object");
161+
jmethodID toString =
162+
env->GetMethodID(object_class, "toString", "()Ljava/lang/String;");
163+
jstring s = (jstring)env->CallObjectMethod(exception, toString);
164+
const char* exception_text = env->GetStringUTFChars(s, nullptr);
165+
166+
// Log the exception text.
167+
__android_log_print(ANDROID_LOG_INFO, FIREBASE_TESTAPP_NAME,
168+
"-------------------JNI exception:");
169+
__android_log_print(ANDROID_LOG_INFO, FIREBASE_TESTAPP_NAME, "%s",
170+
exception_text);
171+
__android_log_print(ANDROID_LOG_INFO, FIREBASE_TESTAPP_NAME,
172+
"-------------------");
173+
174+
// Also, assert fail.
175+
assert(false);
176+
177+
// In the event we didn't assert fail, clean up.
178+
env->ReleaseStringUTFChars(s, exception_text);
179+
env->DeleteLocalRef(s);
180+
env->DeleteLocalRef(exception);
36181
}
37-
return gAppState->destroyRequested;
38182
}
39183

40184
// Log a message that can be viewed in "adb logcat".
41-
int LogMessage(const char* format, ...) {
185+
void LogMessage(const char* format, ...) {
186+
static const int kLineBufferSize = 100;
187+
char buffer[kLineBufferSize + 2];
188+
42189
va_list list;
43-
int rc;
44190
va_start(list, format);
45-
rc = __android_log_vprint(ANDROID_LOG_INFO, FIREBASE_TESTAPP_NAME, format,
46-
list);
191+
int string_len = vsnprintf(buffer, kLineBufferSize, format, list);
192+
string_len = string_len < kLineBufferSize ? string_len : kLineBufferSize;
193+
// append a linebreak to the buffer:
194+
buffer[string_len] = '\n';
195+
buffer[string_len + 1] = '\0';
196+
197+
__android_log_vprint(ANDROID_LOG_INFO, FIREBASE_TESTAPP_NAME, format, list);
198+
g_logging_utils_data->AppendText(buffer);
199+
CheckJNIException();
47200
va_end(list);
48-
return rc;
49201
}
50202

51203
// Get the JNI environment.
52204
JNIEnv* GetJniEnv() {
53-
JavaVM* vm = gAppState->activity->vm;
205+
JavaVM* vm = g_app_state->activity->vm;
54206
JNIEnv* env;
55207
jint result = vm->AttachCurrentThread(&env, nullptr);
56208
return result == JNI_OK ? env : nullptr;
57209
}
58210

59-
// Get the activity.
60-
jobject GetActivity() { return gAppState->activity->clazz; }
61-
62211
// Execute common_main(), flush pending events and finish the activity.
63212
extern "C" void android_main(struct android_app* state) {
64-
int return_value;
65-
gAppState = state;
213+
// native_app_glue spawns a new thread, calling android_main() when the
214+
// activity onStart() or onRestart() methods are called. This code handles
215+
// the case where we're re-entering this method on a different thread by
216+
// signalling the existing thread to exit, waiting for it to complete before
217+
// reinitializing the application.
218+
if (g_started) {
219+
g_restarted = true;
220+
// Wait for the existing thread to exit.
221+
pthread_mutex_lock(&g_started_mutex);
222+
pthread_mutex_unlock(&g_started_mutex);
223+
} else {
224+
g_started_mutex = PTHREAD_MUTEX_INITIALIZER;
225+
}
226+
pthread_mutex_lock(&g_started_mutex);
227+
g_started = true;
228+
229+
// Save native app glue state and setup a callback to track the state.
230+
g_destroy_requested = false;
231+
g_app_state = state;
232+
g_app_state->onAppCmd = OnAppCmd;
233+
234+
// Create the logging display.
235+
g_logging_utils_data = new LoggingUtilsData();
236+
g_logging_utils_data->Init();
237+
238+
// Execute cross platform entry point.
66239
static const char* argv[] = {FIREBASE_TESTAPP_NAME};
67-
return_value = common_main(static_cast<void*>(GetActivity()));
240+
int return_value = common_main(1, argv);
68241
(void)return_value; // Ignore the return value.
69-
ProcessAndroidEvents(10);
70-
ANativeActivity_finish(state->activity);
71-
gAppState->activity->vm->DetachCurrentThread();
242+
ProcessEvents(10);
243+
244+
// Clean up logging display.
245+
delete g_logging_utils_data;
246+
g_logging_utils_data = nullptr;
247+
248+
// Finish the activity.
249+
if (!g_restarted) ANativeActivity_finish(state->activity);
250+
251+
g_app_state->activity->vm->DetachCurrentThread();
252+
g_started = false;
253+
g_restarted = false;
254+
pthread_mutex_unlock(&g_started_mutex);
72255
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2016 Google Inc. All rights reserved.
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+
package com.google.firebase.example;
16+
17+
import android.app.Activity;
18+
import android.os.Handler;
19+
import android.os.Looper;
20+
import android.view.Window;
21+
import android.widget.LinearLayout;
22+
import android.widget.ScrollView;
23+
import android.widget.TextView;
24+
25+
/**
26+
* A utility class, encapsulating the data and methods required to log arbitrary
27+
* text to the screen, via a non-editable TextView.
28+
*/
29+
public class LoggingUtils {
30+
public static TextView sTextView = null;
31+
32+
public static void initLogWindow(Activity activity) {
33+
LinearLayout linearLayout = new LinearLayout(activity);
34+
ScrollView scrollView = new ScrollView(activity);
35+
TextView textView = new TextView(activity);
36+
linearLayout.addView(scrollView);
37+
scrollView.addView(textView);
38+
Window window = activity.getWindow();
39+
window.takeSurface(null);
40+
window.setContentView(linearLayout);
41+
sTextView = textView;
42+
}
43+
44+
public static void addLogText(final String text) {
45+
new Handler(Looper.getMainLooper()).post(new Runnable() {
46+
@Override
47+
public void run() {
48+
if (sTextView != null) {
49+
sTextView.append(text);
50+
}
51+
}
52+
});
53+
}
54+
}

0 commit comments

Comments
 (0)