]> iEval git - fonbot.git/blame - src/ro/ieval/fonbot/RemoteCrashdumpHandler.java
Add SH and ROOTSH commands
[fonbot.git] / src / ro / ieval / fonbot / RemoteCrashdumpHandler.java
CommitLineData
8dfb76c9
MG
1package ro.ieval.fonbot;
2
3import static ro.ieval.fonbot.Utils.toNonNull;
4
5import java.io.ByteArrayOutputStream;
6import java.io.IOException;
7import java.io.PrintStream;
8import java.lang.Thread.UncaughtExceptionHandler;
d13f1533 9import java.util.Collections;
8dfb76c9
MG
10
11import org.eclipse.jdt.annotation.Nullable;
12
13import android.content.Context;
14
15/*
16 * Copyright © 2013 Marius Gavrilescu
17 *
18 * This file is part of FonBot.
19 *
20 * FonBot is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * FonBot is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with FonBot. If not, see <http://www.gnu.org/licenses/>.
32 */
33
34/**
35 * UncaughtExceptionHandler that sends exceptions to the server.
36 *
37 * @author Marius Gavrilescu <marius@ieval.ro>
38 */
39final class RemoteCrashdumpHandler implements UncaughtExceptionHandler {
40 /** Context instance */
41 private final Context context;
42
43 /**
44 * Constructs a RemoteCrashdumpHandler with a given Context instance.
45 *
46 * @param context Context instance
47 */
48 public RemoteCrashdumpHandler(final Context context) {
49 this.context=context;
50 }
51
52 @Override
53 public void uncaughtException(final @Nullable Thread thread, final @Nullable Throwable ex) {
54 if(ex==null)
55 return;
56
57 final ByteArrayOutputStream baos=new ByteArrayOutputStream(16384);
58 final PrintStream pw=new PrintStream(baos);
59 ex.printStackTrace(pw);
60 pw.close();
61
2e5049c9 62 new HttpCallExecutableRunnable("/crashdump", toNonNull(Collections.<Header>emptyList()),
b26f32d6 63 toNonNull(context), null, false, toNonNull(baos.toByteArray())).execute();
8dfb76c9
MG
64
65 try {
66 baos.close();
67 } catch (IOException e) {//NOPMD close exceptions are unimportant
68 //ignored
69 }
70 }
71
72}
This page took 0.044486 seconds and 4 git commands to generate.