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 ;
3030static bool g_destroy_requested = false ;
3131static bool g_started = false ;
3232static bool g_restarted = false ;
3333static 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.
4242bool 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; }
5757jobject 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:
9595class 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.
152152void 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 ;
0 commit comments