OLD | NEW |
| (Empty) |
1 /* | |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
3 * Copyright (C) 2006-2016 Eyeo GmbH | |
4 * | |
5 * Adblock Plus is free software: you can redistribute it and/or modify | |
6 * it under the terms of the GNU General Public License version 3 as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
16 */ | |
17 | |
18 package org.adblockplus.libadblockplus; | |
19 | |
20 import java.util.concurrent.LinkedBlockingQueue; | |
21 | |
22 import org.adblockplus.android.Utils; | |
23 | |
24 import android.util.Log; | |
25 | |
26 public final class JniExceptionHandler | |
27 { | |
28 private final static String TAG = Utils.getTag(JniExceptionHandler.class); | |
29 | |
30 private static LogWorker logWorker = null; | |
31 | |
32 static | |
33 { | |
34 logWorker = new LogWorker(); | |
35 final Thread t = new Thread(logWorker); | |
36 t.setDaemon(true); | |
37 t.start(); | |
38 } | |
39 | |
40 public static void logException(final Throwable t) | |
41 { | |
42 logWorker.logException(t); | |
43 } | |
44 | |
45 private final static class LogWorker implements Runnable | |
46 { | |
47 LinkedBlockingQueue<Throwable> exceptionQueue = new LinkedBlockingQueue<Thro
wable>(); | |
48 | |
49 private void logException(final Throwable t) | |
50 { | |
51 this.exceptionQueue.offer(t); | |
52 } | |
53 | |
54 @Override | |
55 public void run() | |
56 { | |
57 for (;;) | |
58 { | |
59 try | |
60 { | |
61 final Throwable t = this.exceptionQueue.take(); | |
62 Log.e(TAG, "Exception from JNI", t); | |
63 } | |
64 catch (final InterruptedException ie) | |
65 { | |
66 break; | |
67 } | |
68 catch (final Throwable ex) | |
69 { | |
70 // TODO: Swallow or log? | |
71 } | |
72 } | |
73 } | |
74 } | |
75 } | |
OLD | NEW |