mirror of https://github.com/M66B/NetGuard.git
Native report error number
This will allow different errors to have their own notification
This commit is contained in:
parent
b037fe8727
commit
5efacada27
|
@ -32,7 +32,7 @@
|
|||
-keep class eu.faircode.netguard.Packet { *; }
|
||||
-keep class eu.faircode.netguard.SinkholeService {
|
||||
void nativeExit(java.lang.String);
|
||||
void nativeError(java.lang.String);
|
||||
void nativeError(int, java.lang.String);
|
||||
void logPacket(eu.faircode.netguard.Packet);
|
||||
void dnsResolved(eu.faircode.netguard.ResourceRecord);
|
||||
boolean isDomainBlocked(java.lang.String);
|
||||
|
|
|
@ -1181,9 +1181,9 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
}
|
||||
|
||||
// Called from native code
|
||||
private void nativeError(String message) {
|
||||
Log.w(TAG, "Native message=" + message);
|
||||
showErrorNotification(message);
|
||||
private void nativeError(int error, String message) {
|
||||
Log.w(TAG, "Native error " + error + ": " + message);
|
||||
showErrorNotification(error, message);
|
||||
}
|
||||
|
||||
// Called from native code
|
||||
|
@ -1746,7 +1746,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
NotificationManagerCompat.from(this).notify(NOTIFY_EXIT, notification.build());
|
||||
}
|
||||
|
||||
private void showErrorNotification(String message) {
|
||||
private void showErrorNotification(int error, String message) {
|
||||
Intent main = new Intent(this, ActivityMain.class);
|
||||
main.putExtra(ActivityMain.EXTRA_LOGCAT, true);
|
||||
PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_ERROR, main, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
@ -1758,6 +1758,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText(message)
|
||||
.setContentIntent(pi)
|
||||
.setNumber(error)
|
||||
.setColor(tv.data)
|
||||
.setOngoing(false)
|
||||
.setAutoCancel(true);
|
||||
|
@ -1770,7 +1771,7 @@ public class SinkholeService extends VpnService implements SharedPreferences.OnS
|
|||
NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
|
||||
notification.bigText(message);
|
||||
|
||||
NotificationManagerCompat.from(this).notify(NOTIFY_ERROR, notification.build());
|
||||
NotificationManagerCompat.from(this).notify(error + 100, notification.build());
|
||||
}
|
||||
|
||||
private void showAccessNotification(int uid) {
|
||||
|
|
|
@ -139,7 +139,7 @@ void handle_ip(const struct arguments *args,
|
|||
if (ip4hdr->frag_off & IP_MF) {
|
||||
log_android(ANDROID_LOG_ERROR, "IP fragment offset %u", ip4hdr->frag_off & IP_OFFMASK);
|
||||
flags[flen++] = '+';
|
||||
report_error(args, "TCP fragmentation");
|
||||
report_error(args, 2, "TCP fragmentation");
|
||||
}
|
||||
|
||||
uint8_t ipoptlen = (uint8_t) ((ip4hdr->ihl - 5) * 4);
|
||||
|
@ -196,7 +196,7 @@ void handle_ip(const struct arguments *args,
|
|||
// TODO checksum
|
||||
}
|
||||
else {
|
||||
log_android(ANDROID_LOG_WARN, "Unknown version %d", version);
|
||||
log_android(ANDROID_LOG_ERROR, "Unknown version %d", version);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ void handle_ip(const struct arguments *args,
|
|||
// TODO checksum
|
||||
}
|
||||
else if (protocol)
|
||||
report_error(args, "Unknown protocol %d", protocol);
|
||||
report_error(args, 1, "Unknown protocol %d", protocol);
|
||||
|
||||
flags[flen] = 0;
|
||||
|
||||
|
|
|
@ -338,9 +338,9 @@ void report_exit(const struct arguments *args, const char *fmt, ...) {
|
|||
(*args->env)->DeleteLocalRef(args->env, cls);
|
||||
}
|
||||
|
||||
void report_error(const struct arguments *args, const char *fmt, ...) {
|
||||
void report_error(const struct arguments *args, jint error, const char *fmt, ...) {
|
||||
jclass cls = (*args->env)->GetObjectClass(args->env, args->instance);
|
||||
jmethodID mid = jniGetMethodID(args->env, cls, "nativeError", "(Ljava/lang/String;)V");
|
||||
jmethodID mid = jniGetMethodID(args->env, cls, "nativeError", "(ILjava/lang/String;)V");
|
||||
|
||||
jstring jreason = NULL;
|
||||
if (fmt != NULL) {
|
||||
|
@ -352,7 +352,7 @@ void report_error(const struct arguments *args, const char *fmt, ...) {
|
|||
va_end(argptr);
|
||||
}
|
||||
|
||||
(*args->env)->CallVoidMethod(args->env, args->instance, mid, jreason);
|
||||
(*args->env)->CallVoidMethod(args->env, args->instance, mid, error, jreason);
|
||||
jniCheckException(args->env);
|
||||
|
||||
if (jreason != NULL)
|
||||
|
|
|
@ -285,7 +285,7 @@ void *handle_events(void *a);
|
|||
|
||||
void report_exit(const struct arguments *args, const char *fmt, ...);
|
||||
|
||||
void report_error(const struct arguments *args, const char *fmt, ...);
|
||||
void report_error(const struct arguments *args, jint error, const char *fmt, ...);
|
||||
|
||||
void check_allowed(const struct arguments *args);
|
||||
|
||||
|
|
Loading…
Reference in New Issue