UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
android_system.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24 */
25 
26 #include <unistd.h>
27 #include <sys/time.h>
28 #include <stdlib.h>
29 #include <sys/stat.h>
30 #include <sys/types.h>
31 #include <pwd.h>
32 #include <dlfcn.h>
33 #include <fcntl.h>
34 #include <locale.h>
35 #include <signal.h>
36 #include <dirent.h>
37 
38 #include "../../common/common.h"
39 #include "../system.h"
40 
41 #include <android/log.h>
42 #include "../android/android_debugger.h"
43 
44 const char *Sys_GetCurrentUser (void)
45 {
46  char * user = getenv("USER");
47  if (user)
48  return user;
49  return "Player";
50 }
51 
57 void Sys_Error (const char *error, ...)
58 {
59  va_list argptr;
60  char string[1024];
61 
62  Sys_Backtrace();
63 
64 #ifdef COMPILE_UFO
67 #endif
68 
69 #ifdef COMPILE_MAP
70  Mem_Shutdown();
71 #endif
72 
73  va_start(argptr,error);
74  Q_vsnprintf(string, sizeof(string), error, argptr);
75  va_end(argptr);
76 
77  __android_log_print(ANDROID_LOG_FATAL, "UFOAI", "Error: %s", string);
78 
79  exit(1);
80 }
81 
86 void Sys_Quit (void)
87 {
88 #ifdef COMPILE_UFO
89  CL_Shutdown();
92 #elif COMPILE_MAP
93  Mem_Shutdown();
94 #endif
95 
96  exit(0);
97 }
98 
102 void Sys_Backtrace (void)
103 {
104 #ifdef COMPILE_UFO
106 #endif
107 
108  const char *dumpFile = "crashdump.txt";
109  FILE *file = Sys_Fopen(dumpFile, "w");
110  FILE *crash = file != nullptr ? file : stderr;
111 
112  fprintf(crash, "======start======\n");
113 
114  fprintf(crash, BUILDSTRING ", cpu: " CPUSTRING ", version: " UFO_VERSION "\n\n");
115  fflush(crash);
116 
117  androidDumpBacktrace(crash);
118 
119  fprintf(crash, "======end========\n");
120 
121  if (file != nullptr)
122  fclose(file);
123 
124 #ifdef COMPILE_UFO
125  Com_UploadCrashDump(dumpFile);
126 #endif
127 }
void Com_BreakIntoDebugger(void)
Definition: common.cpp:470
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
Definition: shared.cpp:535
void Mem_Shutdown(void)
Definition: mem.cpp:603
#define CPUSTRING
Definition: common.h:109
#define FILE
Definition: test_webapi.cpp:30
static const char * user
Definition: test_webapi.cpp:35
void Sys_Backtrace(void)
On platforms supporting it, print a backtrace.
#define UFO_VERSION
Definition: common.h:36
#define BUILDSTRING
Definition: common.h:121
const char * Sys_GetCurrentUser(void)
void Com_UploadCrashDump(const char *crashDumpFile)
Definition: common.cpp:683
void CL_Shutdown(void)
Saves configuration file and shuts the client systems down.
Definition: cl_main.cpp:1220
void Qcommon_Shutdown(void)
Definition: common.cpp:1537
void Sys_ConsoleShutdown(void)
FILE * Sys_Fopen(const char *filename, const char *mode)
Definition: unix_files.cpp:240
void androidDumpBacktrace(FILE *out)
void Sys_Quit(void)
void Sys_Error(const char *error,...)
Errors out of the game.