2015-11-02 19:09:04 +00:00
|
|
|
package eu.faircode.netguard;
|
|
|
|
|
2015-11-03 17:57:29 +00:00
|
|
|
/*
|
|
|
|
This file is part of NetGuard.
|
|
|
|
|
|
|
|
NetGuard is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
NetGuard is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-12-29 08:27:58 +00:00
|
|
|
Copyright 2015-2017 by Marcel Bokhorst (M66B)
|
2015-11-03 17:57:29 +00:00
|
|
|
*/
|
|
|
|
|
2017-08-08 09:10:51 +00:00
|
|
|
import android.annotation.TargetApi;
|
2015-11-02 19:09:04 +00:00
|
|
|
import android.app.Application;
|
2017-08-12 11:12:43 +00:00
|
|
|
import android.app.Notification;
|
2017-07-31 08:53:37 +00:00
|
|
|
import android.app.NotificationChannel;
|
|
|
|
import android.app.NotificationManager;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.media.AudioAttributes;
|
2017-08-08 09:10:51 +00:00
|
|
|
import android.os.Build;
|
2015-11-02 19:09:04 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
|
|
|
public class ApplicationEx extends Application {
|
|
|
|
private static final String TAG = "NetGuard.App";
|
|
|
|
|
|
|
|
private Thread.UncaughtExceptionHandler mPrevHandler;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate() {
|
|
|
|
super.onCreate();
|
2016-03-09 07:24:16 +00:00
|
|
|
Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
|
2015-11-02 19:09:04 +00:00
|
|
|
|
2017-08-08 09:10:51 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
|
|
|
createNotificationChannels();
|
2017-07-31 08:53:37 +00:00
|
|
|
|
2015-11-02 19:09:04 +00:00
|
|
|
mPrevHandler = Thread.getDefaultUncaughtExceptionHandler();
|
|
|
|
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
|
|
|
@Override
|
|
|
|
public void uncaughtException(Thread thread, Throwable ex) {
|
|
|
|
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
2017-10-28 14:08:06 +00:00
|
|
|
System.exit(1);
|
2015-11-02 19:09:04 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-08-08 09:10:51 +00:00
|
|
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.O)
|
|
|
|
private void createNotificationChannels() {
|
|
|
|
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
|
|
|
|
|
|
|
NotificationChannel foreground = new NotificationChannel("foreground", getString(R.string.channel_foreground), NotificationManager.IMPORTANCE_MIN);
|
2017-08-12 11:12:43 +00:00
|
|
|
foreground.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
2017-08-08 09:10:51 +00:00
|
|
|
nm.createNotificationChannel(foreground);
|
|
|
|
|
|
|
|
NotificationChannel notify = new NotificationChannel("notify", getString(R.string.channel_notify), NotificationManager.IMPORTANCE_DEFAULT);
|
2017-08-12 11:12:43 +00:00
|
|
|
notify.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
2017-08-08 09:10:51 +00:00
|
|
|
nm.createNotificationChannel(notify);
|
|
|
|
|
|
|
|
NotificationChannel access = new NotificationChannel("access", getString(R.string.channel_access), NotificationManager.IMPORTANCE_DEFAULT);
|
2017-08-12 11:12:43 +00:00
|
|
|
access.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
2017-08-08 09:10:51 +00:00
|
|
|
nm.createNotificationChannel(access);
|
|
|
|
}
|
2015-11-02 19:09:04 +00:00
|
|
|
}
|