Skip to content

Commit a90467b

Browse files
committed
readme updates, formatted source
1 parent 3bbb472 commit a90467b

File tree

7 files changed

+183
-176
lines changed

7 files changed

+183
-176
lines changed

gma/testapp/readme.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ Getting Started
126126
127127
### Desktop
128128
- Note: the testapp has no user interface, but the output can be viewed via
129-
the console. Note that the GMA SDK uses a stubbed implementation on
130-
desktop, so functionality is not expected.
129+
the console. The GMA SDK uses a stubbed implementation on desktop, so
130+
functionality is not expected, and the app will end waiting for the interstitial
131+
ad to be dismissed.
131132
- Register your app with Firebase.
132133
- Create a new app on the [Firebase console](https://firebase.google.com/console/),
133134
following the above instructions for Android or iOS.
@@ -176,7 +177,7 @@ Support
176177
License
177178
-------
178179
179-
Copyright 2016 Google, Inc.
180+
Copyright 2022 Google, Inc.
180181
181182
Licensed to the Apache Software Foundation (ASF) under one or more contributor
182183
license agreements. See the NOTICE file distributed with this work for

gma/testapp/src/android/android_main.cc

+29-28
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,33 @@
1717

1818
#include <android/log.h>
1919
#include <android_native_app_glue.h>
20-
#include <pthread.h>
2120
#include <cassert>
21+
#include <pthread.h>
2222

23-
#include "main.h" // NOLINT
23+
#include "main.h" // NOLINT
2424

2525
// This implementation is derived from http://github.com/google/fplutil
2626

27-
extern "C" int common_main(int argc, const char* argv[]);
27+
extern "C" int common_main(int argc, const char *argv[]);
2828

29-
static struct android_app* g_app_state = nullptr;
29+
static struct android_app *g_app_state = nullptr;
3030
static bool g_destroy_requested = false;
3131
static bool g_started = false;
3232
static bool g_restarted = false;
3333
static pthread_mutex_t g_started_mutex;
3434

3535
// Handle state changes from via native app glue.
36-
static void OnAppCmd(struct android_app* app, int32_t cmd) {
36+
static void OnAppCmd(struct android_app *app, int32_t cmd) {
3737
g_destroy_requested |= cmd == APP_CMD_DESTROY;
3838
}
3939

4040
// Process events pending on the main thread.
4141
// Returns true when the app receives an event requesting exit.
4242
bool ProcessEvents(int msec) {
43-
struct android_poll_source* source = nullptr;
43+
struct android_poll_source *source = nullptr;
4444
int events;
4545
int looperId = ALooper_pollAll(msec, nullptr, &events,
46-
reinterpret_cast<void**>(&source));
46+
reinterpret_cast<void **>(&source));
4747
if (looperId >= 0 && source) {
4848
source->process(g_app_state, source);
4949
}
@@ -57,7 +57,7 @@ jobject GetActivity() { return g_app_state->activity->clazz; }
5757
jobject GetWindowContext() { return g_app_state->activity->clazz; }
5858

5959
// 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) {
60+
jclass FindClass(JNIEnv *env, jobject activity_object, const char *class_name) {
6161
jclass class_object = env->FindClass(class_name);
6262
if (env->ExceptionCheck()) {
6363
env->ExceptionClear();
@@ -93,22 +93,21 @@ jclass FindClass(JNIEnv* env, jobject activity_object, const char* class_name) {
9393

9494
// Vars that we need available for appending text to the log window:
9595
class LoggingUtilsData {
96-
public:
96+
public:
9797
LoggingUtilsData()
98-
: logging_utils_class_(nullptr),
99-
logging_utils_add_log_text_(0),
98+
: logging_utils_class_(nullptr), logging_utils_add_log_text_(0),
10099
logging_utils_init_log_window_(0) {}
101100

102101
~LoggingUtilsData() {
103-
JNIEnv* env = GetJniEnv();
102+
JNIEnv *env = GetJniEnv();
104103
assert(env);
105104
if (logging_utils_class_) {
106105
env->DeleteGlobalRef(logging_utils_class_);
107106
}
108107
}
109108

110109
void Init() {
111-
JNIEnv* env = GetJniEnv();
110+
JNIEnv *env = GetJniEnv();
112111
assert(env);
113112

114113
jclass logging_utils_class = FindClass(
@@ -130,27 +129,28 @@ class LoggingUtilsData {
130129
logging_utils_init_log_window_, GetActivity());
131130
}
132131

133-
void AppendText(const char* text) {
134-
if (logging_utils_class_ == 0) return; // haven't been initted yet
135-
JNIEnv* env = GetJniEnv();
132+
void AppendText(const char *text) {
133+
if (logging_utils_class_ == 0)
134+
return; // haven't been initted yet
135+
JNIEnv *env = GetJniEnv();
136136
assert(env);
137137
jstring text_string = env->NewStringUTF(text);
138138
env->CallStaticVoidMethod(logging_utils_class_, logging_utils_add_log_text_,
139139
text_string);
140140
env->DeleteLocalRef(text_string);
141141
}
142142

143-
private:
143+
private:
144144
jclass logging_utils_class_;
145145
jmethodID logging_utils_add_log_text_;
146146
jmethodID logging_utils_init_log_window_;
147147
};
148148

149-
LoggingUtilsData* g_logging_utils_data;
149+
LoggingUtilsData *g_logging_utils_data;
150150

151151
// Checks if a JNI exception has happened, and if so, logs it to the console.
152152
void CheckJNIException() {
153-
JNIEnv* env = GetJniEnv();
153+
JNIEnv *env = GetJniEnv();
154154
if (env->ExceptionCheck()) {
155155
// Get the exception text.
156156
jthrowable exception = env->ExceptionOccurred();
@@ -161,7 +161,7 @@ void CheckJNIException() {
161161
jmethodID toString =
162162
env->GetMethodID(object_class, "toString", "()Ljava/lang/String;");
163163
jstring s = (jstring)env->CallObjectMethod(exception, toString);
164-
const char* exception_text = env->GetStringUTFChars(s, nullptr);
164+
const char *exception_text = env->GetStringUTFChars(s, nullptr);
165165

166166
// Log the exception text.
167167
__android_log_print(ANDROID_LOG_INFO, FIREBASE_TESTAPP_NAME,
@@ -182,7 +182,7 @@ void CheckJNIException() {
182182
}
183183

184184
// Log a message that can be viewed in "adb logcat".
185-
void LogMessage(const char* format, ...) {
185+
void LogMessage(const char *format, ...) {
186186
static const int kLineBufferSize = 100;
187187
char buffer[kLineBufferSize + 2];
188188

@@ -201,15 +201,15 @@ void LogMessage(const char* format, ...) {
201201
}
202202

203203
// Get the JNI environment.
204-
JNIEnv* GetJniEnv() {
205-
JavaVM* vm = g_app_state->activity->vm;
206-
JNIEnv* env;
204+
JNIEnv *GetJniEnv() {
205+
JavaVM *vm = g_app_state->activity->vm;
206+
JNIEnv *env;
207207
jint result = vm->AttachCurrentThread(&env, nullptr);
208208
return result == JNI_OK ? env : nullptr;
209209
}
210210

211211
// Execute common_main(), flush pending events and finish the activity.
212-
extern "C" void android_main(struct android_app* state) {
212+
extern "C" void android_main(struct android_app *state) {
213213
// native_app_glue spawns a new thread, calling android_main() when the
214214
// activity onStart() or onRestart() methods are called. This code handles
215215
// the case where we're re-entering this method on a different thread by
@@ -236,17 +236,18 @@ extern "C" void android_main(struct android_app* state) {
236236
g_logging_utils_data->Init();
237237

238238
// Execute cross platform entry point.
239-
static const char* argv[] = {FIREBASE_TESTAPP_NAME};
239+
static const char *argv[] = {FIREBASE_TESTAPP_NAME};
240240
int return_value = common_main(1, argv);
241-
(void)return_value; // Ignore the return value.
241+
(void)return_value; // Ignore the return value.
242242
ProcessEvents(10);
243243

244244
// Clean up logging display.
245245
delete g_logging_utils_data;
246246
g_logging_utils_data = nullptr;
247247

248248
// Finish the activity.
249-
if (!g_restarted) ANativeActivity_finish(state->activity);
249+
if (!g_restarted)
250+
ANativeActivity_finish(state->activity);
250251

251252
g_app_state->activity->vm->DetachCurrentThread();
252253
g_started = false;

gma/testapp/src/android/java/com/google/firebase/example/LoggingUtils.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public static void initLogWindow(Activity activity) {
4444

4545
public static void addLogText(final String text) {
4646
new Handler(Looper.getMainLooper()).post(new Runnable() {
47-
@Override
48-
public void run() {
49-
if (sTextView != null) {
50-
sTextView.append(text);
51-
}
47+
@Override
48+
public void run() {
49+
if (sTextView != null) {
50+
sTextView.append(text);
5251
}
53-
});
52+
}
53+
});
5454
}
5555
}

0 commit comments

Comments
 (0)