altosdroid: Disable debug output on release builds
[fw/altos] / altosdroid / src / org / altusmetrum / AltosDroid / AltosDebug.java
1 /*
2  * Copyright © 2015 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17 package org.altusmetrum.AltosDroid;
18
19 import java.util.Arrays;
20 import java.io.*;
21 import java.lang.*;
22
23 import org.altusmetrum.altoslib_7.*;
24
25 import android.app.Activity;
26 import android.graphics.*;
27 import android.os.Bundle;
28 import android.support.v4.app.Fragment;
29 import android.support.v4.app.FragmentTransaction;
30 import android.view.*;
31 import android.widget.*;
32 import android.location.Location;
33 import android.content.*;
34 import android.util.Log;
35 import android.os.*;
36 import android.content.pm.*;
37
38 public class AltosDebug {
39         // Debugging
40         static final String TAG = "AltosDroid";
41
42         static boolean  D = true;
43
44         static void init(Context context) {
45                 ApplicationInfo app_info = context.getApplicationInfo();
46
47                 if ((app_info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
48                         Log.d(TAG, "Enable debugging\n");
49                         D = true;
50                 } else {
51                         Log.d(TAG, "Disable debugging\n");
52                         D = false;
53                 }
54         }
55
56
57         static void info(String format, Object ... arguments) {
58                 Log.i(TAG, String.format(format, arguments));
59         }
60
61         static void debug(String format, Object ... arguments) {
62                 if (D)
63                         Log.d(TAG, String.format(format, arguments));
64         }
65
66         static void error(String format, Object ... arguments) {
67                 Log.e(TAG, String.format(format, arguments));
68         }
69
70         static void check_ui(String format, Object ... arguments) {
71                 if (Looper.myLooper() == Looper.getMainLooper()) {
72                         Log.e(TAG, String.format("ON UI THREAD " + format, arguments));
73                         for (StackTraceElement el : Thread.currentThread().getStackTrace())
74                                 Log.e(TAG, "\t" + el.toString() + "\n");
75                 }
76         }
77 }