diff --git a/NetworkGenie/.gitignore b/NetworkGenie/.gitignore index b7a15f2..aa724b7 100644 --- a/NetworkGenie/.gitignore +++ b/NetworkGenie/.gitignore @@ -1,15 +1,15 @@ *.iml .gradle /local.properties -/.idea -/.idea/workspace.xml +/.idea/caches /.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml .DS_Store /build /captures -/tools/config.sh -/app/.externalNativeBuild -/app/release -/app/play -keystore.properties -crowdin.properties +.externalNativeBuild +.cxx +local.properties diff --git a/NetworkGenie/ADBLOCKING.md b/NetworkGenie/ADBLOCKING.md deleted file mode 100644 index f3169e5..0000000 --- a/NetworkGenie/ADBLOCKING.md +++ /dev/null @@ -1,105 +0,0 @@ -Ad Blocking with NetGuard -------------------------- - -Instructions (you need to follow **all** the steps): - -1. Download/install the latest NetGuard version [from GitHub](https://github.com/M66B/NetGuard/releases) (ad blocking is not possible with the Play store version because Google does not allow ad blocking apps in the Play store) -1. Enable the setting *'Filter traffic'* in the advanced options (three dot menu > Settings > Advanced options > Filter traffic; default is disabled except always enabled in Android 5.0 and earlier) -1. Enable the setting *'Block domain names'* in the advanced options (three dot menu > Settings > Advanced options > Block domain names; default is enabled) -1. Import or download [a hosts file](https://en.wikipedia.org/wiki/Hosts_(file)) using the NetGuard backup settings (three dot menu > Settings > Backup > Download hosts file) -1. Disable browser compression (in Chrome: three dot menu > Settings > Lite mode > Off) -1. Wait at least 10 minutes to let the Android DNS cache time out (clear via Chrome: [chrome://net-internals/#dns](chrome://net-internals/#dns)) -1. Test to see if ad blocking works by opening [this page](http://www.netguard.me/test) -1. Enjoy ad blocking, but don't forget to support application developers and website authors in other ways - -
- -Troubleshooting: - -Because of routing bugs, some devices/Android versions require: - -* the advanced option *Manage system applications* to be enabled and/or -* the network option *Subnet routing* to be disabled and/or -* two (not just one) DNS server addresses to be set in the advanced options, for example 8.8.8.8 and 8.8.4.4 or more privacy friendly [these](https://dns.watch/) -* disabling of private DNS - -
- -Note that: - -* applications, like web browsers, may cache data, so you may need to clear caches -* applications, browsers mostly, that have a *"data saver"*-like feature that proxies requests through their servers (eg. Opera w/ Turbo, Opera Max, Puffin, Chrome w/ data saver, UC Browser, Yandex w/ Turbo, Apus Browser, KK Browser, Onavo Extend, Maxthon) will not have ads blocked as NetGuard cannot see those domain requests -* applications, browsers mostly, can have a private DNS feature (Chrome: three-dots menu, Settings, Privacy, Use secure DNS, turn off) ** -* applications, including browser, can be system apps, which require managing system apps in the advanced settings to be enabled -* the Android always-on VPN setting *Block connections without VPN* will result in stop sending domain names to the VPN after some time -* YouTube ads are not domain-based, and thus cannot be blocked with NetGuard -* NetGuard ignores the IP addresses in the hosts file, because it does not route blocked domains to localhost -* When NetGuard imports the hosts file, it automatically discards any duplicates entries, so duplicate entries are not a problem and have no performance impact after the file is imported -* you can check the number of hosts (domains) imported by pulling the NetGuard notification down using two fingers if your version of Android supports that functionality -* wildcards are not supported due to performance and battery usage reasons -* it is not possible to edit the hosts file (change/add/delete domain names) with NetGuard -* you can disable ad blocking by disabling the setting *'Block domain names'* in the advanced options -* you cannot exclude a single app from ad blocking because Android resolves domain names on behalf of all apps -* **ad blocking is provided as-is**, see also [here](https://forum.xda-developers.com/showpost.php?p=71805655&postcount=4668) -* **ad blocking is not available when NetGuard was installed from the Google Play store!** (disable automatic updates of NetGuard in the Play store application) - -** Some browsers (and also apps) now use DNS over TLS (DoT) or DNS over -HTTPS (DoH). If one of the two protocols is active in the browser, -NetGuard cannot "see" the outgoing DNS requests (due to encryption). -They still flow through NetGuard, but are not treated as DNS requests, -but as normal connections (via port 853 or 443). It is therefore not -sufficient to disable Private DNS within Android, but you must also -check the settings for DoT and DoH (especially for browsers). - -
- -The NetGuard version from GitHub: - -* is signed with the same signature as the version from the Google Play store, so any purchases will be restored (this will not happen with for example the F-Droid version) -* will automatically notify you if there are updates available via GitHub (this can be switched off in NetGuard's settings) - -
- -Which hosts (ad servers) will be blocked depends on the hosts file being used. -NetGuard downloads the [StevenBlack hosts file](https://github.com/StevenBlack/hosts) by default. - -
- -Automation: - -You can automatically download a hosts file by sending this service intent with your favorite automation tool, like Tasker: - -`eu.faircode.netguard.DOWNLOAD_HOSTS_FILE` - -For example using [adb](https://developer.android.com/studio/command-line/adb.html) from the command line: - -`adb shell am startservice -a eu.faircode.netguard.DOWNLOAD_HOSTS_FILE` - -
- -Apart from using a hosts file, you can block most in-app ads by blocking this address in the access list of Google Play services: - -*googleads.g.doubleclick.net/443* - -You'll need to enable filtering and (temporarily) logging for this (you can do this by using the *Configure* button; check both options) -and you'll need to wait until the address appears (you can speed this up by opening some apps with in-app ads). -Note that ads are likely being cached, so this may not take effect immediately. - -
- -An alternate way to block advertisements is by using special DNS servers, like these: - -* [AdGuard DNS](https://adguard.com/en/adguard-dns/overview.html) - Free -* [Alternate DNS](https://alternate-dns.com/) - 14 day free trial -* [NoAd](https://noad.zone/) - Not working as of 2017 June 03 - -Be sure to read the privacy policies of these services as they might log your DNS requests. - -You can set DNS server addresses for all connection types in NetGuard's *Advanced options*. -Note that when you set two DNS server addresses, the default (operating system/network provider) DNS servers will not be used anymore. - -Feel free to let me know about other servers or request to add them in alphabetic order by doing a pull request. - -
- -**Please do not mention this feature in Google Play store comments, since Google does not allow ad blocking applications in the Google Play store.** diff --git a/NetworkGenie/FAQ-de.txt b/NetworkGenie/FAQ-de.txt deleted file mode 100644 index 21ea20d..0000000 --- a/NetworkGenie/FAQ-de.txt +++ /dev/null @@ -1,500 +0,0 @@ -Häufig gestellte Fragen (FAQ) - -(0) Wie verwende ich NetGuard? - - Aktivieren Sie die NetGuard-Firewall über den Schalter in der Aktionsleiste von NetGuard - Erlauben (grünlich*) oder verweigern (rötlich*) Sie den Wi-Fi- oder mobilen Internetzugang über die Symbole neben den Anwendungsnamen in der Anwendungsliste des NetGuard - -Über Einstellungen > Standardeinstellungen können Sie vom Modus "Blockieren/Blacklist" (Deaktivieren von "Wi-Fi blockieren" und "Mobile blockieren" und anschließendes Blockieren unerwünschter Anwendungen in der Anwendungsliste des NetGuard) in den Modus "Zulassen/Whitelist" (Aktivieren von "Wi-Fi blockieren" und "Mobile blockieren" und anschließendes Zulassen gewünschter Anwendungen in der Anwendungsliste des NetGuard) wechseln. - -* Je nach dem von Ihnen verwendeten Thema können die Symbole wie folgt aussehen: - - Erlaubt (Internetzugang erlaubt): grünlich (teal) / blau / lila / grau - Blockiert (Internetzugang verweigert): rötlich (lachsfarben) / orange / gelb / gelb - -(1) Kann NetGuard meine Privatsphäre vollständig schützen? - -Nein - nichts kann Ihre Privatsphäre vollständig schützen. NetGuard tut sein Bestes, ist aber durch die Tatsache eingeschränkt, dass es den Android-VPN-Dienst verwenden muss. Dies ist der Kompromiss, der erforderlich ist, um eine Firewall zu entwickeln, die keinen Root-Zugriff erfordert. Die Firewall kann nur gestartet werden, wenn Android den Start "erlaubt". Sie bietet also keinen Schutz beim frühen Hochfahren (obwohl Sie Ihr Netzwerk vor dem Neustart deaktivieren können). Außerdem muss der Android-VPN-Dienst neu gestartet werden, um neue Regeln anzuwenden, wenn sich die Konnektivität geändert hat oder wenn der Bildschirm ein- oder ausgeschaltet wird. Das ist jedoch viel besser als gar nichts. - -In den erweiterten Optionen können Sie Seamless VPN Handover on reload aktivieren, um zu verhindern, dass Datenverkehr verloren geht, wenn der Android VPN-Dienst neu gestartet wird. Dies funktioniert jedoch nicht bei allen Android-Versionen/Varianten und führt dazu, dass NetGuard hängen bleibt und alle Verbindungen blockiert. - -Unter Android N und höher kann NetGuard als Always-On VPN konfiguriert werden. Aktivieren Sie unter Android O nicht die Unteroption "Verbindungen ohne VPN blockieren", siehe Frage 51) für weitere Informationen dazu. - -Um sich besser zu schützen, denken Sie daran, Wi-Fi und mobile Daten vor dem Neustart zu deaktivieren und sie erst beim Neustart zu aktivieren, nachdem der Firewall-Dienst gestartet wurde (und das Schlüsselsymbol in der Statusleiste sichtbar ist). - -Vielen Dank @pulser - -(2) Kann ich eine andere VPN-Anwendung verwenden, während ich NetGuard nutze? - -Wenn die VPN-Anwendung den VPN-Dienst nutzt, dann nicht, denn NetGuard muss diesen Dienst nutzen. Android erlaubt immer nur einer Anwendung, diesen Dienst zu nutzen. - -NetGuard ist eine Firewall-Anwendung, es ist also nicht beabsichtigt, VPN-Unterstützung hinzuzufügen. NetGuard unterstützt jedoch einen SOCKS5-Proxy zur Verkettung von VPN-Anwendungen. Eine mögliche Lösung, die von der Community beigesteuert wurde, finden Sie hier. - -3) Kann ich NetGuard auf jeder Android-Version verwenden? - -Nein, die minimal erforderliche Android-Version ist 5.1 (Lollipop). - -(4) Verbraucht NetGuard zusätzliche Akkuleistung? - -In der Standardeinstellung verbraucht NetGuard kaum Akkuleistung. Alle Einstellungen, die zusätzlichen Akkuverbrauch verursachen, wie IP-Filterung und Protokollierung, sind mit einer Warnung versehen. Wenn NetGuard sehr viel Strom verbraucht, überprüfen Sie bitte Ihre Einstellungen. - -Der Akkuverbrauch bei aktivierter IP-Filterung hängt von der Qualität der Implementierung Ihres Android-VPN-Dienstes und der Leistungsfähigkeit des Prozessors Ihres Geräts ab. Im Allgemeinen kann der Akkuverbrauch auf älteren Geräten inakzeptabel sein, während er auf modernen Geräten mit einem effizienten Prozessor kaum auffällt. - -Die Benachrichtigung über die Netzwerkgeschwindigkeitsgrafik verbraucht zusätzliche Akkuleistung. Deshalb wird die Benachrichtigung nur angezeigt, wenn der Bildschirm eingeschaltet ist. Sie können die Aktualisierungshäufigkeit in den Einstellungen verringern, um den Akkuverbrauch zu reduzieren. - -Beachten Sie, dass Android oft fälschlicherweise den Akkuverbrauch anderer Anwendungen dem NetGuard zuordnet, da der Netzwerkverkehr anderer Anwendungen durch den NetGuard fließt. Das bedeutet, dass es so aussehen kann, als würde NetGuard viel Akkuleistung verbrauchen, aber in Wirklichkeit ist der Gesamtakkuverbrauch aller Apps immer noch derselbe. - -(6) Sendet NetGuard meinen Internetverkehr an einen externen (VPN-)Server? - -Nein, je nach Betriebsmodus geschieht grundsätzlich eines von zwei Dingen mit Ihrem Internetverkehr: - - Wenn die IP-Filterung deaktiviert ist, wird der blockierte Internetverkehr an den lokalen VPN-Dienst weitergeleitet, der dann als Sinkhole fungiert (d.h. den gesamten blockierten Verkehr verwirft). - Wenn die IP-Filterung aktiviert ist, wird sowohl der blockierte als auch der erlaubte Internetverkehr in den lokalen VPN-Dienst geleitet und nur der erlaubte Verkehr wird an das vorgesehene Ziel weitergeleitet (und nicht an einen VPN-Server). - -Der Android-VPN-Dienst wird verwendet, um den gesamten Internetverkehr lokal zu NetGuard zu leiten, so dass für die Erstellung dieser Firewall-Anwendung kein Root-Recht erforderlich ist. NetGuard ist im Gegensatz zu allen anderen No-Root-Firewall-Anwendungen zu 100 % Open Source, so dass Sie im Zweifelsfall den Quellcode selbst überprüfen können. - -(7) Warum werden Anwendungen ohne Internetzulassung angezeigt? - -Die Internetzugangsberechtigung kann bei jedem Anwendungsupdate ohne Zustimmung des Benutzers erteilt werden. Indem NetGuard alle Anwendungen anzeigt, können Sie den Internetzugang kontrollieren, noch bevor ein solches Update erfolgt. - -(8) Was muss ich aktivieren, damit die Google Play™ Store-App funktioniert? - -Sie müssen 3 Pakete (Anwendungen) aktivieren (verwenden Sie die Suche in NetGuard, um sie schnell zu finden): - - com.android.vending (Play Store) - com.google.android.gms (Play-Dienste) - com.android.providers.downloads (Download-Manager) - -Da die Google Play™ Store-App dazu neigt, von sich aus nach Updates zu suchen oder sie sogar herunterzuladen (auch wenn kein Konto damit verknüpft ist), kann man sie in Schach halten, indem man "Bei eingeschaltetem Bildschirm zulassen" für alle 3 Pakete aktiviert. Klicken Sie auf den Pfeil nach unten auf der linken Seite eines Anwendungsnamens und aktivieren Sie diese Option, aber lassen Sie die Netzwerksymbole auf rot stehen (daher blockiert). Das kleine menschliche Symbol wird für diese Pakete angezeigt. - -Beachten Sie, dass NetGuard die Installation eines Google-Dienstes nicht erfordert. - -(9) Warum wird der VPN-Dienst neu gestartet? - -Der VPN-Dienst wird neu gestartet, wenn Sie den Bildschirm ein- oder ausschalten und wenn sich die Konnektivität ändert (Wi-Fi, Mobilfunk), um die Regeln mit den Bedingungen "Zulassen, wenn der Bildschirm eingeschaltet ist" und "Blockieren, wenn Roaming" anzuwenden. - -Siehe hier für weitere Details. - -(10) Werden Sie ein Tasker-Plug-in anbieten? - -Nein, denn wenn es Tasker erlaubt ist, den NetGuard zu deaktivieren, kann jede Anwendung den NetGuard deaktivieren. Es ist keine gute Idee, einer Sicherheitsanwendung zu erlauben, von anderen Anwendungen deaktiviert zu werden. - - -(13) Wie kann ich den laufenden NetGuard-Eintrag auf dem Benachrichtigungsbildschirm entfernen? - - Klicken Sie lange auf die NetGuard-Benachrichtigung - Tippen Sie auf das "i"-Symbol - Je nach den Software-Anpassungen Ihres Geräts und/oder ROM-Herstellers werden Sie entweder zu - zum Bildschirm "App-Info", wo Sie das Häkchen bei "Benachrichtigungen anzeigen" entfernen und dem nächsten Dialog zustimmen können - zum Bildschirm "App-Benachrichtigungen", wo Sie den Schieberegler "Blockieren" auf "Ein" stellen können - -Beachten Sie, dass unabhängig davon, ob Sie eine Dialogwarnung erhalten oder nicht, dieser Vorgang auch alle Informations- oder Warnbenachrichtigungen von NetGuard deaktiviert, wie z. B. die Benachrichtigung über eine neu installierte Anwendung. - -Um zu erfahren, warum diese Benachrichtigung überhaupt notwendig ist, lesen Sie bitte Frage 24. - -Einige Android-Versionen zeigen eine zusätzliche Benachrichtigung an, die ein Schlüsselsymbol enthalten kann. Diese Benachrichtigung kann leider nicht entfernt werden. - -(14) Warum kann ich nicht OK wählen, um die VPN-Verbindungsanfrage zu bestätigen? - -Möglicherweise befindet sich eine weitere (unsichtbare) Anwendung über dem Dialog für die VPN-Verbindungsanfrage. Einige bekannte (den Bildschirm verdunkelnde) Anwendungen, die dies verursachen können, sind Lux Brightness, Night Mode und Twilight. Um dieses Problem zumindest vorübergehend zu vermeiden, schließen Sie alle Anwendungen und/oder Dienste, die im Hintergrund ausgeführt werden können. - -(15) Werden F-Droid-Builds unterstützt? - -F-Droid-Builds werden nicht unterstützt, da ich keine Kontrolle darüber habe, ob und wann die F-Droid-Version von NetGuard aktualisiert wird, so dass ich keine rechtzeitigen Updates garantieren kann, z. B. wenn es ein kritisches oder Sicherheitsproblem gibt. - -Da F-Droid-Builds und GitHub-Versionen unterschiedlich signiert sind, muss ein F-Droid-Build zuerst deinstalliert werden, um auf eine GitHub-Version aktualisieren zu können. - -(16) Warum werden einige Anwendungen abgeblendet angezeigt? - -Deaktivierte Anwendungen und Anwendungen ohne Internetzugang werden abgeblendet dargestellt. - -(17) Warum verbraucht der NetGuard so viel Speicher? - -Das tut er nicht. NetGuard weist keinen Speicher zu, außer ein wenig für die Anzeige der Elemente der Benutzeroberfläche und für die Pufferung des Datenverkehrs. Bei einigen Android-Varianten scheint die Verbindung mit der Google Play™ Store-App fast 150 MB zu verbrauchen. Sie wird für In-App-Spenden benötigt und wird fälschlicherweise NetGuard statt der Google Play™ Store-App zugewiesen. - -(18) Warum kann ich NetGuard nicht in der Google Play™-Store-App finden? - -NetGuard erfordert mindestens Android 5.1 und ist daher in der Google Play™ Store-App auf Geräten mit früheren Android-Versionen nicht verfügbar. - -(18) Warum kann ich NetGuard nicht in der Google Play™ Store-App finden? - -NetGuard erfordert mindestens Android 5.1 und ist daher in der Google Play™ Store-App auf Geräten mit früheren Android-Versionen nicht verfügbar. - -(19) Warum hat die Anwendung XYZ immer noch Internetzugang? - -Wenn Sie den Internetzugang für eine Anwendung sperren, gibt es keine Möglichkeit, dies zu umgehen. Anwendungen können jedoch über andere (System-)Anwendungen/Komponenten auf das Internet zugreifen. So erhalten beispielsweise die Google Play-Dienste eingehende Push-Nachrichten und Werbung für die meisten Anwendungen, einschließlich WhatsApp und Facebook Messenger. Sie können dies verhindern, indem Sie den Internetzugang auch für die andere Anwendung/Komponente blockieren. Sie können Systemanwendungen und -komponenten wie Google Play Services blockieren, indem Sie die erweiterte NetGuard-Option Systemanwendungen verwalten aktivieren. Dies lässt sich am besten diagnostizieren, indem Sie das globale Zugriffsprotokoll überprüfen (Drei-Punkte-Menü, Protokoll anzeigen). - -Beachten Sie, dass einige Anwendungen immer wieder versuchen, auf das Internet zuzugreifen, was durch das Senden eines Verbindungsanforderungspakets geschieht. Dieses Paket geht in das VPN-Sinkhole, wenn der Internetzugang für die Anwendung blockiert ist. Dieses Paket besteht aus weniger als 100 Bytes und wird von Android als ausgehender Datenverkehr gezählt und ist auch in der Geschwindigkeitsanzeige sichtbar. - -(20) Kann ich den NetGuard "grün" machen/bewerben? - -Nein. Wenn Sie den NetGuard auf "grün" stellen oder anderweitig in den Ruhezustand versetzen, werden die Regeln nicht angewendet, wenn sich die Konnektivität von Wi-Fi/Mobilfunk, Bildschirm ein/aus und Roaming/nicht Roaming ändert. - -(21) Wirkt sich der Dämmerungsmodus auf den NetGuard aus? - -Ich bin mir nicht sicher, denn aus der Dokumentation zum Dämmerungsmodus geht nicht hervor, ob der Android-VPN-Dienst davon betroffen ist. - -Um sicher zu gehen, können Sie die Akku-Optimierung für NetGuard wie folgt manuell deaktivieren: - -Android-Einstellungen > Akku > Drei-Punkte-Menü > Akku-Optimierungen > Dropdown > Alle Apps > NetGuard > Nicht optimieren > Fertig - -Die Vorgehensweise kann von Gerät zu Gerät unterschiedlich sein. - -Das Deaktivieren des Standby-Modus für NetGuard kann nicht von NetGuard aus erfolgen, da NetGuard laut Google kein Anwendungstyp ist, der dies tun darf. - -(22) Kann ich mit dem NetGuard Tethering (Android-Hotspot) oder Wi-Fi-Anrufe nutzen? - -Ja, aber Sie müssen das Subnetz-Routing und Tethering in den NetGuard-Netzwerkeinstellungen aktivieren. Ob dies funktioniert, hängt von Ihrer Android-Version ab, da einige Android-Versionen einen Fehler aufweisen, der die Zusammenarbeit zwischen Tethering und dem VPN-Dienst verhindert. - -Einige Geräte schalten das Wi-Fi in den Ruhezustand, so dass Tethering nicht funktioniert, wenn der Bildschirm ausgeschaltet ist. Dieses Verhalten kann in den erweiterten Wi-Fi-Einstellungen von Android deaktiviert werden. - -(24) Kann man die Benachrichtigung aus der Statusleiste entfernen? - -Android kann Hintergrunddienste jederzeit beenden. Dies kann nur verhindert werden, indem ein Hintergrunddienst in einen Vordergrunddienst umgewandelt wird. Android verlangt eine ständige Benachrichtigung für alle Vordergrunddienste, um Sie auf einen möglichen Batterieverbrauch aufmerksam zu machen (siehe Frage 4). Die Benachrichtigung kann also nicht entfernt werden, ohne Instabilität zu verursachen. Allerdings wird die Benachrichtigung als niedrige Priorität markiert, was dazu führen sollte, dass sie an das Ende der Liste verschoben wird. - -Das Schlüsselsymbol und/oder die Benachrichtigung "VPN läuft", die von Android und nicht von NetGuard angezeigt wird, kann leider nicht entfernt werden. In der Google-Dokumentation steht: "Eine vom System verwaltete Benachrichtigung wird während der Lebensdauer einer VPN-Verbindung angezeigt". - -Android 8 Oreo und höher zeigen eine Benachrichtigung "... läuft im Hintergrund" an, die alle im Hintergrund laufenden Apps auflistet. Sie können diese Benachrichtigung nicht deaktivieren, aber Sie können das Symbol wie folgt aus der Statusleiste entfernen: - - Öffnen Sie Einstellungen > Apps & Benachrichtigungen > App-Info - Öffnen Sie die Einstellungen (drei Punkte); Wählen Sie "System anzeigen". - Wählen Sie "Android-System". - Wählen Sie "App-Benachrichtigungen". - Wählen Sie "Im Hintergrund laufende Apps". - Wählen Sie "Wichtigkeit" und wählen Sie "Niedrig". - -(25) Können Sie eine Funktion "Alle auswählen" hinzufügen? - -Die Funktion "Alle auswählen" ist nicht erforderlich, da Sie in den Einstellungen von Netguard vom Modus "Blockieren" (Blacklist) auf "Zulassen" (Whitelist) umschalten können. Siehe auch Frage 0. - -(27) Wie lese ich das Protokoll des blockierten Datenverkehrs? - -Die Spalten haben die folgenden Bedeutungen: - - Zeit (tippen Sie auf einen Protokolleintrag, um das Datum zu sehen) - Anwendungssymbol (tippen Sie auf einen Protokolleintrag, um den Anwendungsnamen zu sehen) - UID der Anwendung - Wi-Fi / mobile Verbindung, grün=erlaubt, rot=geblockt - Interaktiver Status (Bildschirm an oder aus) - Protokoll (siehe unten) und Paketflags (siehe unten) - Quell- und Zielport (tippen Sie auf einen Protokolleintrag, um einen Zielport zu suchen) - Quell- und Ziel-IPv4- oder IPv6-Adresse (tippen Sie auf einen Protokolleintrag, um eine Ziel-IP-Adresse nachzuschlagen) - Name der Organisation, der die IP-Adresse gehört (muss über das Menü aktiviert werden) - -Protokolle: - - HOPO (IPv6 Hop-by-Hop-Option) - ICMP - IGMP - ESP (IPSec) - TCP - UDP - Nummer = eines der Protokolle in dieser Liste - 4 = IPv4 - 6 = IPv6 - -Paket-Flags: - - S = SYN - A = ACK - P = PSH - F = FIN - R = RST - -Eine ausführliche Erklärung finden Sie hier. - -Nur TCP-, UDP- und ICMP-Ping-Datenverkehr kann durch den Android VPN-Dienst geleitet werden. Alle anderen Daten werden verworfen und im globalen Datenverkehrsprotokoll als blockiert angezeigt. Dies ist auf einem Android-Gerät fast nie ein Problem. - -(28) Warum wird den Google-Konnektivitätsdiensten standardmäßig der Internetzugang gestattet? - -Die Systemanwendung der Google-Konnektivitätsdienste prüft, ob das aktuelle Netzwerk wirklich mit dem Internet verbunden ist. Dies wird wahrscheinlich durch eine kurze Verbindung zu einem Google-Server erreicht. - -Wenn dies nicht der Fall ist, erscheint ein '!' im Wi-Fi- oder Mobil-Symbol in der Systemstatusleiste. - -Neuere Android-Versionen scheinen die Konnektivität nicht von Mobil auf Wi-Fi umzuschalten, wenn das Wi-Fi-Netzwerk nicht wirklich verbunden ist, obwohl eine Verbindung zum Wi-Fi-Netzwerk besteht (oder umgekehrt). Unter Android 6.0 und höher erhalten Sie möglicherweise eine Benachrichtigung, in der Sie gefragt werden, ob Sie die Verbindung aufrechterhalten möchten oder nicht. Um eine schlechte Benutzererfahrung zu vermeiden, enthält NetGuard eine vordefinierte Regel, um die Google-Konnektivitätsdienste standardmäßig zuzulassen. - -Sie können alle vordefinierten Regeln hier finden. - -Sie können vordefinierte Regeln außer Kraft setzen. - -(29) Warum erhalte ich die Meldung "Das von Ihnen angeforderte Element ist nicht zum Kauf verfügbar"? - -Sie können nur Pro-Funktionen erwerben, wenn Sie NetGuard aus dem Google Play Store installiert haben. - -(30) Kann ich auch AFWall+ auf demselben Gerät ausführen? - -Sofern Sie NetGuard nicht nur testen, gibt es derzeit keinen Grund, beide zu verwenden, da sie dieselbe Funktion (Firewall) abdecken, wenn auch mit unterschiedlichen Grundvoraussetzungen (AFWall+ benötigt ein gerootetes Gerät) und Vorgehensweisen (AFWall+ verwendet iptables, während NetGuard ein VPN verwendet). - -Außerdem müssen Sie die Zugriffsregeln für jede Anwendung zwischen AFWall+ und NetGuard synchron halten, da die Anwendung sonst nicht auf das Netzwerk zugreifen kann. - -Einige Hinweise zur Einrichtung von AFWall+ für den gleichzeitigen Einsatz mit NetGuard: - - Wenn Sie keine Filterung in NetGuard verwenden, benötigen die Anwendungen direkten Internetzugang (Wi-Fi und/oder mobil) in AFWall+ - Wenn Sie die Filterung verwenden, benötigt NetGuard einen Internetzugang (Wi-Fi und/oder mobil) in AFWall+ - Wenn Sie die Filterung verwenden, müssen Sie NetGuard in AFWall+ wieder zulassen, wenn Sie NetGuard deinstallieren/neu installieren. - Wenn Sie die Filterung verwenden, benötigen die Anwendungen einen VPN-Internetzugang (aktivieren Sie das Kontrollkästchen, um diese Option in den AFWall+-Einstellungen anzuzeigen). - -Diese Frage wurde von der Community gestellt. Es gibt keine Unterstützung für die Verwendung von NetGuard und AFWall+ zusammen. - -(31) Warum können einige Anwendungen nur als Gruppe konfiguriert werden? - -Für viele Zwecke, einschließlich des Netzwerkzugriffs, gruppiert Android Anwendungen nach UID und nicht nach Paket/Anwendungsname. Insbesondere Systemanwendungen haben oft dieselbe UID, obwohl sie einen anderen Paket- und Anwendungsnamen haben; diese werden vom ROM-Hersteller bei der Erstellung so eingerichtet. Diesen Anwendungen kann nur als Gruppe der Zugang zum Internet erlaubt/gesperrt werden. - -(32) Warum ist der Akku-/Netzwerkverbrauch von NetGuard so hoch? - -Das liegt daran, dass Android die Batterie- und Netzwerknutzung zählt, die normalerweise für andere Anwendungen gegen NetGuard im IP-Filtermodus gezählt wird. Der gesamte Akkuverbrauch ist etwas höher, wenn der IP-Filtermodus aktiviert ist. Der IP-Filtermodus ist bei Android-Versionen vor 5.0 immer aktiviert, bei späteren Android-Versionen ist er optional. - -(33) Können Sie Profile hinzufügen? - -Profile sind unpraktisch, da sie manuell bedient werden müssen. Bedingungen wie "Wenn der Bildschirm eingeschaltet ist" sind dagegen praktisch, weil sie automatisch funktionieren. Daher werden keine Profile hinzugefügt, aber Sie können gerne neue Bedingungen vorschlagen; diese müssen jedoch allgemein verwendbar sein, um aufgenommen zu werden. - -Als Abhilfe können Sie die Export-/Importfunktion verwenden, um bestimmte Einstellungen unter bestimmten Umständen anzuwenden. Alternativ können Sie auch den Sperrmodus als Profil verwenden. - -(34) Können Sie eine Bedingung "wenn im Vordergrund" oder "wenn aktiv" hinzufügen? - -Aktuelle Android-Versionen erlauben es einer Anwendung nicht, abzufragen, ob andere Anwendungen im Vordergrund/Hintergrund oder aktiv/inaktiv sind, ohne eine zusätzliche, die Privatsphäre verletzende Berechtigung zu besitzen und auf Kosten eines zusätzlichen Batterieverbrauchs (da eine regelmäßige Abfrage erforderlich ist). Daher kann dies nicht ohne erhebliche Nachteile, wie diesen, hinzugefügt werden. Sie können stattdessen die Bedingung "wenn der Bildschirm eingeschaltet ist" verwenden. - -(35) Warum startet das VPN nicht? - -NetGuard "bittet" Android, den lokalen VPN-Dienst zu starten, aber einige Android-Versionen enthalten einen Fehler, der den (automatischen) Start des VPN verhindert. Manchmal wird dies durch ein Update von NetGuard verursacht. Leider kann dieser Fehler nicht von NetGuard behoben werden. Sie können versuchen, Ihr Gerät neu zu starten und/oder die VPN-Berechtigungen von NetGuard über die Android-Einstellungen zu widerrufen. Manchmal hilft es auch, NetGuard zu deinstallieren und neu zu installieren (exportieren Sie vorher unbedingt Ihre Einstellungen!). - -(36) Können Sie einen PIN- oder Passwortschutz hinzufügen? - -Da das Ausschalten des VPN-Dienstes über die Android-Einstellungen nicht verhindert werden kann, ist es wenig sinnvoll, einen PIN- oder Passwortschutz hinzuzufügen. - -(37) Warum sind die Profi-Funktionen so teuer? - -Die richtige Frage lautet: "Warum gibt es so viele Steuern und Gebühren": - - Mehrwertsteuer: 25% (abhängig von Ihrem Land) - Google-Gebühr: 30% - Einkommenssteuer: 50% - -Was für den Entwickler übrig bleibt, ist also nur ein Bruchteil dessen, was Sie bezahlen. - -Obwohl NetGuard wirklich viel Arbeit macht, müssen nur einige der Komfort- und erweiterten Funktionen gekauft werden, was bedeutet, dass NetGuard im Grunde kostenlos ist und Sie nichts bezahlen müssen, um Ihren Datenverbrauch zu reduzieren, die Akkulaufzeit zu erhöhen und Ihre Privatsphäre zu schützen. - -Beachten Sie auch, dass die meisten kostenlosen Anwendungen am Ende nicht nachhaltig zu sein scheinen, während NetGuard ordnungsgemäß gewartet und unterstützt wird, und dass kostenlose Anwendungen einen Haken haben können, wie z. B. das Senden von datenschutzrelevanten Informationen an das Internet. - -Siehe hier für weitere Informationen. - -(38) Warum hat NetGuard aufgehört zu laufen? - -Vergewissern Sie sich zunächst, dass Sie in den Android-Einstellungen die Akku-Optimierung für NetGuard deaktiviert haben. - -Auf den meisten Geräten läuft der NetGuard im Hintergrund mit seinem Dienst im Vordergrund weiter. Auf einigen Geräten (insbesondere einigen Samsung-Modellen), auf denen viele Anwendungen um den Speicher konkurrieren, kann Android NetGuard als letzte Möglichkeit noch stoppen. Einige Android-Versionen, insbesondere von Huawei (siehe hier für einen Fix) oder Xiaomi (siehe hier für einen Fix) stoppen Apps und Dienste zu aggressiv. Dies kann leider nicht von NetGuard behoben werden und kann als Mangel des Gerätes und/oder als Fehler in Android angesehen werden. In der Tat leiden viele Apps unter diesem Problem, siehe die Website Don't kill my app! für weitere Informationen und Lösungen. Sie können dieses Problem umgehen, indem Sie in den erweiterten Optionen des NetGuard den Watchdog aktivieren, der alle 10-15 Minuten überprüft. - -(39) Wie unterscheidet sich eine VPN-basierte Firewall von einer iptables-basierten Firewall? - -Siehe diese Stack Exchange-Frage. - -(40) Kann man Zeitpläne hinzufügen? - -Abgesehen davon, dass es nicht trivial ist, Zeitpläne hinzuzufügen, sind sie - meiner Meinung nach - keine gute Idee, da Zeit keine gute Regelbedingung ist. Eine Regelbedingung wie Wenn der Bildschirm eingeschaltet ist ist eine bessere und einfachere Bedingung. Daher werden keine Zeitpläne hinzugefügt, aber Sie können gerne andere neue Bedingungen vorschlagen. - -(41) Können Sie Wildcards / Adress-/Portbereiche hinzufügen? - -Wildcards zum Zulassen/Blockieren von Adressen und Adress-/Anschlussbereichen hätten erhebliche Auswirkungen auf die Leistung und Benutzerfreundlichkeit und werden daher nicht hinzugefügt. Wildcard-Regeln und Adress-/Port-Bereiche müssten für jeden einzelnen Verbindungsversuch überprüft werden. Da NetGuard im Gegensatz zu anderen No-Root-Firewalls Domänennamen anstelle von IP-Adressen blockiert, gibt es kaum einen Bedarf für Wildcards. - -(42) Warum wird die Berechtigung ... benötigt? - - INTERNET ('Voller Netzwerkzugriff'): um erlaubten (gefilterten) Datenverkehr an das Internet weiterzuleiten - ACCESS_NETWORK_STATE ("Netzwerkverbindungen anzeigen"): um zu prüfen, ob das Gerät über Wi-Fi mit dem Internet verbunden ist - READ_PHONE_STATE ('Device ID & call information'): um Änderungen im Mobilfunknetz zu erkennen, siehe hier für weitere Details - ACCESS_WIFI_STATE ("Wi-Fi-Verbindungsinformationen"): zur Erkennung von Änderungen im Wi-Fi-Netzwerk - RECEIVE_BOOT_COMPLETED ('Run at startup'): zum Starten der Firewall beim Booten des Geräts - WAKE_LOCK ("Gerät am Schlafen hindern"): zum zuverlässigen Neuladen von Regeln im Hintergrund bei Änderungen der Konnektivität - VIBRATE: um eine Vibrationsrückmeldung beim Antippen des Widgets zu geben - FOREGROUND_SERVICE ('Vordergrunddienst'): zur Ausführung eines Vordergrunddienstes unter Android 9 Pie und höher - QUERY_ALL_PACKAGES: zum Auflisten aller Apps unter Android 11 und höher - BILLING: zur Verwendung der In-App-Abrechnung - -(43) Ich erhalte die Meldung "Diese App führt dazu, dass Ihr Gerät langsam läuft". - -Diese Meldung wird vom Smart Manager angezeigt, aber eigentlich ist es die Smart Manager-Anwendung selbst, die Verzögerungen und Lags verursacht. Einige Links: - - Smart Manager beschwert sich über LastPass - Smart Manager deaktivieren? -(44) Ich erhalte keine Benachrichtigungen beim Zugriff - -Um eine hohe Anzahl von Benachrichtigungen in der Statusleiste zu vermeiden, wird die Benachrichtigung bei Zugriff nur einmal pro Domainname und Anwendung durchgeführt. Zugriffe auf Domänennamen, die im Zugriffsprotokoll der Anwendung angezeigt werden (Drilldown in den NetGuard-Anwendungseinstellungen), werden nicht erneut benachrichtigt, selbst wenn Sie die Benachrichtigung bei Zugriff gerade aktiviert haben. Um wieder für alle Domainnamen benachrichtigt zu werden, können Sie das Anwendungszugriffsprotokoll über das Mülleimer-Symbol löschen. Wenn Sie alle Anwendungsprotokolle löschen möchten, können Sie Ihre Einstellungen exportieren und importieren. - -Ein weiterer Grund, warum Sie keine Benachrichtigungen erhalten, könnte ein aktivierter Energiesparmodus sein, z. B. bei Samsung-Geräten. Auch wenn Sie die CPU-Frequenz in diesem Modus nicht einschränken. - -(45) Verarbeitet NetGuard eingehende Verbindungen? - -Der Android VPN-Dienst behandelt nur ausgehende Verbindungen (von Anwendungen zum Internet), eingehende Verbindungen werden also normalerweise nicht behandelt. - -Wenn Sie eine Serveranwendung auf Android ausführen möchten, sollten Sie beachten, dass die Verwendung von Portnummern unter 1024 Root-Berechtigungen erfordert und dass einige Android-Versionen Routing-Fehler enthalten, die dazu führen, dass eingehender Datenverkehr fälschlicherweise in das VPN geleitet wird. - -(46) Kann ich eine Rückerstattung erhalten? - -Wenn eine gekaufte Pro-Funktion nicht wie beschrieben funktioniert und dies nicht durch ein Problem in den kostenlosen Funktionen verursacht wird und ich das Problem nicht zeitnah beheben kann, können Sie eine Rückerstattung erhalten. In allen anderen Fällen ist eine Rückerstattung nicht möglich. In keinem Fall kann es eine Rückerstattung für ein Problem im Zusammenhang mit den kostenlosen Funktionen geben, da für diese nichts bezahlt wurde und sie ohne Einschränkung bewertet werden können. Ich übernehme die Verantwortung als Verkäufer, das zu liefern, was versprochen wurde, und ich erwarte, dass Sie die Verantwortung übernehmen, sich über das zu informieren, was Sie kaufen. - -(48) Warum werden einige Domänennamen blockiert, obwohl sie als erlaubt eingestellt sind? - -NetGuard blockiert den Datenverkehr auf der Grundlage der IP-Adressen, mit denen eine Anwendung versucht, eine Verbindung herzustellen. Wenn mehr als ein Domänenname auf dieselbe IP-Adresse verweist, können sie nicht unterschieden werden. Wenn Sie für 2 Domänen, die auf dieselbe IP-Adresse aufgelöst werden, unterschiedliche Regeln festlegen, werden beide blockiert. - -Danke @pulser - -Ein weiteres mögliches Problem ist, dass Android den DNS-TTL-Wert nicht beachtet und seine eigenen Caching-Regeln anwendet. Dies könnte dazu führen, dass NetGuard einen DNS-Eintrag zu früh oder zu spät aus seinem eigenen Cache löscht, was dazu führt, dass eine IP-Adresse nicht oder falsch erkannt wird. Sie können versuchen, dieses Problem zu umgehen, indem Sie den DNS-TTL-Wert von NetGuard ändern. Dieser Wert wird als minimaler DNS TTL-Wert verwendet, um das Verhalten von Android zu imitieren. - -NetGuard blockiert den Datenverkehr auch, wenn der Android-VPN-Dienst neu gestartet wird, um neue Regeln anzuwenden, z. B. wenn sich die Konnektivität ändert oder wenn der Bildschirm ein- oder ausgeschaltet wird. - -(49) Verschlüsselt NetGuard meinen Internetverkehr / verbirgt es meine IP-Adresse? - -NetGuard ist eine Firewall-Anwendung, die den Internetverkehr auf Ihrem Gerät filtert (siehe auch diese Frage). Sie ist also nicht dazu gedacht - und tut es auch nicht -, Ihren Internetverkehr zu verschlüsseln oder Ihre IP-Adresse zu verbergen. - -(50) Wird NetGuard beim Booten automatisch gestartet? - -Ja, NetGuard wird beim Hochfahren automatisch gestartet, wenn Sie Ihr Gerät mit aktiviertem NetGuard ausgeschaltet haben und NetGuard nicht auf einem externen Speicher installiert ist. - -Einige Geräte, z. B. OnePlus- und Mi-Geräte, können verhindern, dass bestimmte Apps nach dem Neustart automatisch gestartet werden. Dies kann in den Android-Einstellungen deaktiviert werden. - -(51) Warum blockiert der NetGuard den gesamten Internetverkehr? - -Vergewissern Sie sich, dass Sie NetGuard auf die Doze-Ausnahmeliste gesetzt haben (Android 6 Marshmallow oder höher) und dass Android NetGuard erlaubt, das Internet im Hintergrund zu nutzen (siehe auch diese Frage). - -Stellen Sie sicher, dass Sie NetGuard nicht im Erlaubnismodus (Whitelist) betreiben (überprüfen Sie die Standardeinstellungen von NetGuard). - -Stellen Sie sicher, dass Sie die Always-On-VPN-Unteroption "Verbindungen ohne VPN blockieren" nicht aktiviert haben (Android 8 Oreo oder höher). Dadurch wird auch die Auflösung von Domainnamen blockiert (ist das ein Fehler oder eine Funktion?). - -Einige Internetanbieter blockieren alle DNS-Anfragen, außer über ihre eigenen DNS-Server. Wenn Sie also benutzerdefinierte DNS-Server konfiguriert haben, versuchen Sie, dies rückgängig zu machen. - -Einige Android-Versionen, darunter LineageOS und /e/ für einige Geräte, enthalten einen Fehler, der dazu führt, dass der gesamte Internetverkehr blockiert wird. Meistens können Sie diesen Fehler umgehen, indem Sie die Filterung in den erweiterten Optionen von NetGuard aktivieren. Wenn dies das Problem nicht löst, kann es leider nicht von NetGuard behoben oder umgangen werden. Bitte schauen Sie hier für eine Lösung. - -(52) Was ist der Lockdown-Modus? - -Im Sperrmodus wird der gesamte Datenverkehr für alle Anwendungen blockiert, mit Ausnahme von Anwendungen, für die die Bedingung "Im Sperrmodus zulassen" aktiviert ist. Sie können diesen Modus verwenden, um die Nutzung des Akkus oder des Netzes einzuschränken, z. B. wenn Ihr Akku fast leer ist oder Ihr Datenkontingent fast erschöpft ist. - -Beachten Sie, dass der Sperrmodus nur angewendet werden kann, wenn die entsprechende Option auch unter "Netzwerkoptionen" eingestellt ist (eine für den Wi-Fi-Modus, eine für mobile Daten), so dass die Sperrung nur in einem der beiden Netzwerkmodi und nicht im anderen erfolgen kann (z. B. Sperren, wenn mobile Daten aktiv sind, aber nicht, wenn Wi-Fi gerade verwendet wird). - -Beachten Sie auch, dass Systemanwendungen in diesem Modus nur blockiert werden, wenn die Verwaltung von Systemanwendungen in den erweiterten Einstellungen aktiviert ist. - -Sie können den Sperrmodus im Hauptmenü, über ein Widget oder über eine Einstellungs-Kachel aktivieren/deaktivieren (Android 7 Nougat oder höher). - -(53) Die Übersetzung in meiner Sprache fehlt / ist falsch / unvollständig - -Sie können hier Übersetzungen beisteuern (die Registrierung ist kostenlos). Wenn deine Sprache fehlt, kontaktiere mich bitte, damit ich sie hinzufügen kann. - -(54) Wie kann ich alle TCP-Verbindungen durch das Tor-Netzwerk tunneln? - -Tor mit NetGuard wird nur im XDA NetGuard Forum unterstützt. Es gibt keinen persönlichen Support für Tor mit NetGuard, da ich Tor selbst nicht benutze. - -Installiere zunächst Orbot, den Android-Client für Tor, starte ihn, drücke auf Start, während er sich verbindet, öffne die Einstellungen und stelle sicher, dass er so eingestellt ist, dass er beim Start des Gerätes automatisch startet. - -In den Netzwerkoptionen von NetGuard aktiviere Subnetz-Routing und in den erweiterten Optionen SOCKS5-Proxy verwenden mit der Adresse 127.0.0.1 und dem Port 9050 (das ist der Standard-Port, wenn du ihn in Orbot geändert hast, dann ändere ihn auch hier). - -Das sollte ausreichen. Wenn der Test fehlschlägt (z.B. keine Verbindung), können Sie die App-Details von Orbot öffnen, das Häkchen bei Regeln und Bedingungen anwenden entfernen und es erneut versuchen. - -Wie man testet: Öffne Firefox (oder einen anderen nicht-proxyfähigen Browser) mit der Adresse https://ipleak.net/ und du solltest eine andere IP-Adresse als deine normale sehen, und unten im Feld Tor Exit Node etwas anderes als Unknown. - -Sei dir bewusst, dass alle anderen Tor-Hinweise (https://www.torproject.org/docs/faq.html.en) immer noch gelten, wie z.B. dass das Tor-Netzwerk nicht erreichbar ist, deine Aktivitäten in deinem Land aktiv überwacht/gezielt werden, Online-Dienste (z.B. Gmail, Google Play Store) sich nicht anmelden können oder du gezwungen bist, endlose Capchas zu lösen, wenn du auf Seiten zugreifst, die Cloudflare's CDN-Dienste nutzen. - -(55) Warum verbindet sich NetGuard mit Amazon / ipinfo.io / 216.239.34.21? - -NetGuard stellt eine Verbindung zu Amazon / ipinfo.io her, um die Namen und Organisationen für IP-Adressen anzuzeigen. Wenn Sie dies nicht wünschen, deaktivieren Sie einfach die Anzeige von Namen und Organisationen über das Drei-Punkte-Menü in der globalen Protokollansicht. - -(56) Warum lässt der NetGuard den gesamten Internetverkehr zu? - -NetGuard kann jede einzelne Anwendung blockieren, sogar Systemanwendungen und -komponenten. - -NetGuard lässt standardmäßig jeglichen Datenverkehr zu, um schwer zu findende Probleme zu vermeiden. Sie müssen den Datenverkehr selbst selektiv blockieren, indem Sie auf das Mobil- oder Wi-Fi-Symbol tippen. - -Beachten Sie, dass NetGuard den Datenverkehr zu einer Anwendung zulässt, wenn der Bildschirm eingeschaltet ist und die Bedingung "wenn Bildschirm eingeschaltet" aktiviert ist. - -(57) Warum verbraucht der NetGuard so viele Daten? - -Im Grunde genommen verbraucht NetGuard selbst keine Daten. Bei vielen Android-Versionen werden jedoch die Daten anderer Anwendungen, die durch NetGuard fließen, fälschlicherweise dem NetGuard statt den Anwendungen zugerechnet. In diesem Fall ist der Datenverbrauch anderer Anwendungen bei aktiviertem NetGuard gleich Null. - -Der gesamte Datenverbrauch Ihres Geräts ist mit und ohne NetGuard gleich. - -(58) Warum dauert das Laden der Anwendungsliste so lange? - -Die Anwendungsliste wird von Android bereitgestellt, daher hängt die Ladegeschwindigkeit hauptsächlich von der Leistung Ihres Geräts und der Effizienz Ihrer Android-Version ab. So kann z. B. Speicherknappheit zu längeren Ladezeiten führen, da Speicher freigegeben werden muss, z. B. durch das Pausieren anderer Anwendungen. - -Es ist bekannt, dass die Einschränkung von Systemanwendungen und Systemkomponenten unter bestimmten Umständen dazu führt, dass die Anwendungsliste langsam oder gar nicht geladen wird. Die genauen Umstände sind nicht bekannt. - -(59) Können Sie mir helfen, meinen Kauf wiederherzustellen? - -Google verwaltet alle Käufe, so dass ich als Entwickler keine Kontrolle über die Käufe habe. Daher kann ich Ihnen nur einige Ratschläge geben: - - Stellen Sie sicher, dass Sie eine aktive Internetverbindung haben. - Stellen Sie sicher, dass Sie den Google Play Store / die Play-Dienste nicht blockiert haben. - Vergewissern Sie sich, dass Sie mit dem richtigen Google-Konto angemeldet sind und dass mit Ihrem Google-Konto alles in Ordnung ist. - Stellen Sie sicher, dass Sie NetGuard über das richtige Google-Konto installiert haben, wenn Sie mehrere Google-Konten auf Ihrem Gerät eingerichtet haben - Öffnen Sie die Play Store-App und warten Sie mindestens eine Minute, um ihr Zeit zu geben, sich mit den Google-Servern zu synchronisieren. - Öffnen Sie NetGuard und navigieren Sie zum Bildschirm mit den Profi-Funktionen; NetGuard wird die Einkäufe erneut überprüfen - -Sie können auch versuchen, den Cache der Play Store-App über die Einstellungen der Android-Apps zu löschen. - -Beachten Sie dies: - - Einkäufe werden in der Google-Cloud gespeichert und können nicht verloren gehen. - Es gibt keine zeitliche Begrenzung für Einkäufe, sie können also nicht verfallen - Google gibt keine Details (Name, E-Mail, etc.) über Käufer an Entwickler weiter. - Eine Anwendung wie NetGuard kann nicht auswählen, welches Google-Konto verwendet werden soll. - Es kann eine Weile dauern, bis die Play Store-App einen Kauf mit einem anderen Gerät synchronisiert hat - Play Store-Einkäufe können nicht ohne den Play Store verwendet werden, was nach den Play Store-Regeln ebenfalls nicht zulässig ist - -Wenn Sie das Problem mit dem Kauf nicht lösen können, müssen Sie sich mit Google in Verbindung setzen. - -(60) Warum funktionieren IP (Wi-Fi) Anrufe/SMS/MMS nicht? - -Bitte lesen Sie dazu den Abschnitt über die Kompatibilität (wenn Sie ein mobiles Gerät verwenden, müssen Sie möglicherweise die Desktop-Version anfordern, um diesen Abschnitt zu sehen). - -(61) Hilfe, NetGuard ist abgestürzt! - -NetGuard stürzt selten ab ("unerwartet gestoppt"), aber wenn es abgestürzt ist (was etwas anderes ist, als von Android gestoppt zu werden, siehe diese FAQ), dann liegt es meist an Fehlern in Ihrer Android-Version (entweder in der Implementierung des Android-VPN-Dienstes oder im Android-Linux-Kernel). Ich bin gerne bereit, die Ursache eines Absturzes zu überprüfen und wenn möglich zu beheben, aber dazu benötige ich ein Logcat, das von Ihrem PC mit dem Absturzprotokoll aufgezeichnet wurde. Da Logcats meist recht umfangreich sind, benötige ich auch den genauen Zeitpunkt des Absturzes. Wenn Sie nicht wissen, wie Sie ein Logcat von Ihrem PC erfassen können, verwenden Sie bitte Ihre Lieblingssuchmaschine, um eine der zahlreichen Anleitungen zu finden. - -(62) Wie kann ich das Problem "Es gab ein Problem beim Parsen des Pakets" lösen? - -Wahrscheinliche Ursachen sind, dass die heruntergeladene APK-Datei beschädigt ist (was durch einen Virenscanner verursacht werden könnte) oder dass Sie versuchen, NetGuard auf einer nicht unterstützten Android-Version zu installieren. - -(63) Warum ist der gesamte DNS-Verkehr erlaubt? - -NetGuard blockiert im Gegensatz zu allen anderen Android-Firewalls echte Domainnamen. Hierfür muss eine Liste von Domainnamen und IP-Adressen erstellt werden. Zu diesem Zweck lässt NetGuard jeglichen DNS-Verkehr zu, auch wenn der Domainname in der Hosts-Datei aufgeführt ist. Das bedeutet jedoch nicht, dass der Verkehr zur aufgelösten IP-Adresse erlaubt ist. - -Wenn Sie dem System (Google) oder den DNS-Servern Ihres Providers nicht trauen, können Sie in den erweiterten Einstellungen alternative DNS-Server festlegen. Achten Sie darauf, die Adressen einzugeben und zu bestätigen und zwei DNS-Serveradressen festzulegen. Wenn Sie nur eine DNS-Serveradresse eingeben, wird diese zusätzlich zu den Standard-DNS-Serveradressen verwendet. - -(64) Können Sie DNS über TLS/HTTP hinzufügen? - -Wenn Sie DNS-over-HTTP- (DoH) oder DNS-over-TLS- (DoT) Anfragen abfangen wollen, um Domänennamen aufzulösen, ist dies nicht möglich, da der DoH/DoT-Verkehr verschlüsselt ist, was ja der Sinn von DoH/DoT ist. - -Bitte lesen Sie hier, wie Sie DoH/DoT trotzdem mit NetGuard nutzen können. - -(65) Warum kann sich NetGuard nicht selbst blockieren? - -Zunächst einmal, wenn NetGuard sich selbst blockieren kann, sollten Sie darauf vertrauen, dass NetGuard sich wirklich selbst blockiert, was im Grunde dasselbe ist, wie darauf zu vertrauen, dass NetGuard sich nicht mit dem Internet verbindet, wenn es nicht benötigt wird. - -Beachten Sie, dass NetGuard sich mit dem Internet verbinden muss, um den Datenverkehr anderer Anwendungen an das Internet weiterzuleiten und um Informationen über IP-Adressen nachzuschlagen, siehe auch diese FAQ. - -NetGuard konnte sich in älteren Versionen selbst blockieren, aber das erforderte den Aufruf von VpnService.protect für jede einzelne Verbindung. Da es in einer typischen Android-Umgebung viele Verbindungen von vielen Apps gibt, führte dies zu einer Verschwendung von Batteriestrom und zu Abstürzen auf einigen Android-Versionen mit Fehlern in dieser Funktion. - -Da das Blockieren von NetGuard mit sich selbst nichts Nützliches gebracht hat, wurde das Blockieren von NetGuard mit sich selbst entfernt, um Batteriestrom zu sparen und Abstürze zu vermeiden. - -(66) Warum greift eine blockierte App trotzdem auf das Internet zu? - -Gesperrte Anwendungen können nicht auf das Internet zugreifen. Hierfür gibt es keine Ausnahmen. Der gesamte App- und Systemverkehr fließt durch den Android-VPN-Dienst, was für Unternehmen mit hohen Sicherheitsanforderungen ein Muss ist. Das bedeutet auch, dass alle Apps gleich behandelt werden und dass das globale Zugriffsprotokoll (Protokoll anzeigen im Drei-Punkte-Überlaufmenü) den gesamten Datenverkehr anzeigt. - -Allerdings: - - Apps können lokal zwischengespeicherte Inhalte anzeigen - Eingehende (Push-)Nachrichten werden von der Systemkomponente Google Play-Dienste und nicht von Apps empfangen, insbesondere wenn die App im Hintergrund läuft oder der Bildschirm ausgeschaltet ist. - Ebenso wird Werbung meist von der Systemkomponente Google Play-Dienste empfangen. - Downloads werden oft durch den Download-Manager und nicht durch Apps durchgeführt. - -Wenn Sie Google Play-Dienste oder den Download-Manager blockieren möchten, müssen Sie die Verwaltung von System-Apps in den erweiterten Einstellungen aktivieren. - -Wenn Sie sicherstellen möchten, dass Push-Nachrichten immer empfangen werden, können Sie Regeln und Bedingungen für Google Play-Dienste anwenden deaktivieren. - -Um es klar zu sagen: In den meisten Fällen können Sie Anzeigen nicht durch das Blockieren von Apps blockieren. Sie können jedoch mit NetGuard Werbung für alle Apps blockieren, wie das geht, erfahren Sie hier. - -(67) Wer ist "nobody"? - -"nobody" ist die übliche Bezeichnung für ein Benutzerkonto, das keine Dateien besitzt, in keiner privilegierten Gruppe ist und keine anderen Fähigkeiten hat als die, die jeder andere Benutzer hat. - -NetGuard wird nur für Telefone und Tablets unterstützt, also nicht für andere Gerätetypen wie Fernsehgeräte oder Fahrzeuge. - -Wenn Sie die Antwort auf Ihre Frage nicht gefunden haben, können Sie Ihre Fragen in diesem Forum stellen oder mich über dieses Kontaktformular kontaktieren. - diff --git a/NetworkGenie/FAQ.md b/NetworkGenie/FAQ.md deleted file mode 100644 index 96f7868..0000000 --- a/NetworkGenie/FAQ.md +++ /dev/null @@ -1,751 +0,0 @@ -NetGuard -======== - -Please scroll down if you want to ask a question, request a feature, or report a bug. - -[Deutsche Übersetzung](https://raw.githubusercontent.com/M66B/NetGuard/master/FAQ-de.txt) - -Frequently Asked Questions (FAQ) --------------------------------- - - -**(0) How do I use NetGuard?** - -* Enable the NetGuard firewall using the switch in NetGuard's action bar -* Allow (greenish\*) or deny (reddish\*) Wi-Fi or mobile internet access using the icons next to an application name in NetGuard's applications list - -You can use *Settings > Defaults* to change from block/blacklist mode (disable *Block Wi-Fi* and *Block mobile*, and then block unwanted applications in NetGuard's applications list) to allow/whitelist mode (enable *Block Wi-Fi* and *Block mobile*, and then allow desired applications in NetGuard's applications list). - -\* Depending on the theme you use, the icons may be: -* Allowed (internet access permitted): greenish (teal) / blue / purple / gray -* Blocked (internet access denied): reddish (salmon) / orange / yellow / amber - - -**(1) Can NetGuard completely protect my privacy?** - -No - nothing can completely protect your privacy. -NetGuard will do its best, but it is limited by the fact it must use the Android VPN service. -This is the trade-off required to make a firewall which does not require root access. -The firewall can only start when Android "allows" it to start, -so it will not offer protection during early boot-up (although you can disable your network before rebooting). -Also, the Android VPN service needs to be restarted to apply new rules when connectivity has changed or when the screen is being turned on or off. -It will, however, be much better than nothing. - -In the advanced options you can enable *Seamless VPN handover on reload* to prevent traffic from leaking when the Android VPN service is being restarted. -However, this does not work properly on all Android versions/variants causing NetGuard to hang and block all connections. - -On Android N and later NetGuard can be configured as [Always-On VPN](https://developer.android.com/guide/topics/connectivity/vpn#always-on). -On Android O **do not** enable the sub option '*Block connections without VPN*', see [question 51](#user-content-faq51)) for more information on this. - -To protect yourself more, remember to disable Wi-Fi and mobile data before rebooting, -and only enable them on reboot, after the firewall service has started (and the key icon is visible in the status bar). - -Thanks @[pulser](https://github.com/pulser/) - - -**(2) Can I use another VPN application while using NetGuard** - -If the VPN application is using the [VPN service](http://developer.android.com/reference/android/net/VpnService.html), -then no, because NetGuard needs to use this service. Android allows only one application at a time to use this service. - -NetGuard is a firewall application, so there is no intention to add VPN support. -However, NetGuard supports a [SOCKS5 proxy](https://en.wikipedia.org/wiki/SOCKS) to chain VPN applications. -You can find one possible community contributed solution [here](https://itsignacioportal.github.io/netguard-pdnsf-any-vpn-combo/). - - -**(3) Can I use NetGuard on any Android version?** - -No, the minimum required Android version is 5.1 (Lollipop) - - -**(4) Will NetGuard use extra battery power?** - -By default NetGuard will hardly use any battery power. -All settings resulting in extra battery usage, like IP filtering and logging, have a warning. -If NetGuard uses a lot of battery power, please double check your settings. - -The battery usage when IP filtering is enabled depends on the quality of your Android VPN service implementation and the efficiency of the processor of your device. -Generally the battery usage on older devices might be unacceptable, yet hardly noticeable on modern devices with an efficient processor. - -The network speed graph notification will use extra battery power. -This is why the notification is shown only when the screen is on. -You can decrease the update frequency using the settings to reduce the battery usage. - -Note that Android often incorrectly contribute battery usage of other apps to NetGuard, -because the network traffic of other apps is flowing through NetGuard. -This means that it might look like NetGuard is using a lot of battery power, -but that in fact the total battery usage of all apps is still the same. - - -**(6) Will NetGuard send my internet traffic to an external (VPN) server?** - -No, depending on the mode of operation basically one of two things will happen with your internet traffic: - -* When IP filtering is disabled, blocked internet traffic will be routed into the local VPN service, which will operate as a sinkhole (in effect dropping all blocked traffic) -* When IP filtering is enabled, both blocked and allowed internet traffic will be routed into the local VPN service and only allowed traffic will be forwarded to the intended destination (and not to a VPN server) - -The [Android VPN service](http://developer.android.com/reference/android/net/VpnService.html) is being used to locally route all internet traffic to NetGuard so no root is required to build this firewall application. -NetGuard, unlike all other no-root firewalls applications, is 100% open source, so when you are in doubt you can check [the source code](https://github.com/M66B/NetGuard/) yourself. - - -**(7) Why are applications without internet permission shown?** - -Internet permission can be granted with each application update without user consent. -By showing all applications, NetGuard allows you to control internet access even *before* such an update occurs. - - -**(8) What do I need to enable for the Google Play™ store app to work?** - -You need 3 packages (applications) enabled (use search in NetGuard to find them quickly): - -* com.android.vending (Play store) -* com.google.android.gms (Play services) -* com.android.providers.downloads (Download manager) - -Since the Google Play™ store app has a tendency to check for updates or even download them all by itself (even if no account is associated), -one can keep it in check by enabling "*Allow when screen is on*" for all 3 of these packages. -Click on the down arrow on the left side of an application name and check that option, -but leave the network icons set to red (hence blocked). The little human icon will appear for those packages. - -Note that NetGuard does *not* require any Google service to be installed. - - -**(9) Why is the VPN service being restarted?** - -The VPN service will be restarted when you turn the screen on or off and when connectivity changes (Wi-Fi, mobile) -to apply the rules with the conditions *'Allow when screen is on'* and *'Block when roaming'*. - -See [here](http://forum.xda-developers.com/showpost.php?p=65723629&postcount=1788) for more details. - - -**(10) Will you provide a Tasker plug-in?** - -No, because if Tasker is allowed to disable NetGuard, any application can disable NetGuard. -Allowing a security application to be disabled by other applications is not a good idea. - - -**(13) How can I remove the ongoing NetGuard entry in the notification screen?** - -* Long click the NetGuard notification -* Tap the 'i' icon -* Depending on your device and/or ROM manufacturer's software customizations, you can be directed to either: - * the **App Info** screen and you can uncheck '*Show notifications*' and agree to the next dialog - * the **App Notifications** screen and you can toggle the '*Block*' slider to on - -Note that, whether or not you get a dialog warning to agree upon, -this operation will also disable any information or warning notifications from NetGuard, -such as the new application installed notification. - -To read about the need for the notification in the first place, see [question 24](#user-content-faq24). - -Some Android versions display an additional notification, which might include a key icon. -This notification, unfortunately, cannot be removed. - - -**(14) Why can't I select OK to approve the VPN connection request?** - -There might be another (invisible) application on top of the VPN connection request dialog. -Some known (screen dimming) applications which can cause this are *Lux Brightness*, *Night Mode*, and *Twilight*. -To avoid this problem, at least temporarily, close all applications and/or services which may be running in the background. - - -**(15) Are F-Droid builds supported?** - -F-Droid builds are not supported because I have no control over if and when the F-Droid version of NetGuard will be updated, -so I cannot guarantee timely updates, for example if there is a critical or security issue. - -Because F-Droid builds and GitHub releases are signed differently, an F-Droid build needs to be uninstalled first to be able to update to a GitHub release. - - -**(16) Why are some applications shown dimmed?** - -Disabled applications and applications without internet permission are shown dimmed. - - -**(17) Why is NetGuard using so much memory?** - -It isn't. NetGuard doesn't allocate any memory, except a little for displaying the user interface elements and for buffering traffic. -It appears, on some Android variants, that the Google Play™ store app connection uses almost 150 MB. It is needed for in-app donations, -and is incorrectly attributed to NetGuard instead to the Google Play™ store app. - - -**(18) Why can't I find NetGuard in the Google Play™ store app?** - -NetGuard requires at least Android 5.1, so it is not available in the Google Play™ store app on devices running prior Android versions. - - -**(19) Why does application XYZ still have internet access?** - -If you block internet access for an application, there is no way around it. -However, applications could access the internet through other (system) applications/components. -For example, Google Play services receives incoming push messages and ads for most applications, including WhatsApp and Facebook messenger. -You can prevent this by blocking internet access for the other application/component as well. -You can block system applications and components, like Google Play services, by enabling the advanced NetGuard option *Manage system apps*. -This can best be diagnosed by checking the global access log (three dot menu, *Show log*). - -Note that some applications keep trying to access the internet, which is done by sending a connection request packet. -This packet goes into the VPN sinkhole when internet access for the application is blocked. -This packet consists of less than 100 bytes and is counted by Android as outgoing traffic -and will be visible in the speed graph notification as well. - - -**(20) Can I Greenify/hibernate NetGuard?** - -No. [Greenifying](https://play.google.com/store/apps/details?id=com.oasisfeng.greenify) -or otherwise hibernating NetGuard will result in rules not being applied -when connectivity changes from Wi-Fi/mobile, screen on/off, and roaming/not roaming. - - -**(21) Does doze mode affect NetGuard?** - -I am not sure, because the [doze mode documentation](http://developer.android.com/training/monitoring-device-state/doze-standby.html) -is not clear if the [Android VPN service](http://developer.android.com/reference/android/net/VpnService.html) will be affected. - -To be sure, you can disable battery optimizations for NetGuard manually like this: - -``` -Android settings > Battery > three dot menu > Battery optimizations > Dropdown > All apps > NetGuard > Don't optimize > Done -``` - -The procedure to accomplish this can vary between devices. - -Disabling doze mode for NetGuard cannot be done from within NetGuard -because, according to Google, NetGuard is [not an application type allowed to do this](http://developer.android.com/training/monitoring-device-state/doze-standby.html#whitelisting-cases). - - -**(22) Can I tether (use the Android hotspot) / use Wi-Fi calling while using NetGuard?** - -Yes, but you'll need to enable subnet routing and tethering in the NetGuard network settings. -Whether or not it works depends on your Android version -because some Android versions have a bug preventing tethering and the VPN service working together. - -Some devices hibernate Wi-Fi, preventing tethering from working when the screen is off. -This behavior can be disabled in the Android enhanced/advanced Wi-Fi settings. - - -**(24) Can you remove the notification from the status bar?** - -Android can kill background services at any time. -This can only be prevented by turning a background service into a foreground service. -Android requires an ongoing notification for all foreground services -to make you aware of potential battery usage (see [question 4](#user-content-faq4)). -So, the notification cannot be removed without causing instability. -However, the notification is being marked as low priority, -which should result in moving it to the bottom of the list. - -The key icon and/or the VPN running notification, -which is shown by Android and not by NetGuard, unfortunately, cannot be removed. -The [Google documentation](http://developer.android.com/reference/android/net/VpnService.html) states: -*"A system-managed notification is shown during the lifetime of a VPN connection"*. - -Android 8 Oreo and later display a notification "*... running in the background*" listing all apps running in the background. -You can't disable this notification, but you can remove the icon from the status bar like this: - -* Open Settings > Apps & notifications > App info -* Open settings (three dots); Select "Show system" -* Select "Android System" -* Select "App notifications" -* Select "Apps running in background" -* Select "Importance" and select "Low" - - -**(25) Can you add a 'Select All' function?** - -There is no need for a 'Select All' function -because you can switch from block (blacklist) to allow (whitelist) mode using Netguard's settings. -See also [question 0](#user-content-faq0). - - -**(27) How do I read the blocked traffic log?** - -The columns have the following meanings: - -1. Time (tap on a log entry to see the date) -1. Application icon (tap on a log entry to see the application name) -1. Application UID -1. Wi-Fi / mobile connection, green=allowed, red=blocked -1. Interactive state (screen on or off) -1. Protocol (see below) and packet flags (see below) -1. Source and destination port (tap on a log entry to lookup a destination port) -1. Source and destination IPv4 or IPv6 address (tap on a log entry to lookup a destination IP address) -1. Organization name owning the IP address (needs to be enabled via the menu) - -Protocols: - -* HOPO ([IPv6 Hop-by-Hop Option](https://en.m.wikipedia.org/wiki/IPv6_packet#Hop-by-hop_options_and_destination_options)) -* ICMP -* IGMP -* ESP (IPSec) -* TCP -* UDP -* Number = one of the protocols in [this list](https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers) -* 4 = IPv4 -* 6 = IPv6 - -Packet flags: - -* S = SYN -* A = ACK -* P = PSH -* F = FIN -* R = RST - -For a detailed explanation see [here](https://en.wikipedia.org/wiki/Transmission_Control_Protocol). - -Only TCP, UDP, and ICMP ping traffic can be routed through the Android VPN service. -All other traffic will be dropped and will be shown as blocked in the global traffic log. -This is almost never a problem on an Android device. - - -**(28) Why is Google connectivity services allowed internet access by default?** - -The Google connectivity services system application checks if the current network is really connected to the internet. -This is probably accomplished by briefly connecting to some Google server. - -If this is not the case, there will be an '!' in the Wi-Fi or mobile icon in the system status bar. - -Recent Android versions seem not to switch connectivity from mobile to Wi-Fi when the Wi-Fi network is not really connected, -even though there is a connection to the Wi-Fi network (or the other way around). On Android 6.0 and later you might get a notification asking you if you want to keep this connection on or not. -To prevent a bad user experience, NetGuard includes a predefined rule to default allow the Google connectivity services. - -You can find all predefined rules [here](https://github.com/M66B/NetGuard/blob/master/app/src/main/res/xml/predefined.xml). - -You can override predefined rules. - - -**(29) Why do I get 'The item you requested is not available for purchase'?** - -You can only purchase pro features when you have installed NetGuard from the Google Play store. - - -**(30) Can I also run AFWall+ on the same device?** - -Unless you are just testing NetGuard, there is no current reason to use them both, since they cover the same function (firewall), -although with different base needs (AFWall+ needs a rooted device) and ways of doing their thing (AFWall+ uses iptables whereas NetGuard uses a VPN). - -Also you need to keep per application access rules _always_ in sync between AFWall+ and NetGuard, -else the application will not be able to access the network, -hence bringing another level of complexity when setting and assuring everything work as expected. - -Some pointers on how to set up AFWall+ to be used simultaneously with NetGuard: -* if not using filtering in NetGuard, applications _need_ direct internet access (Wi-Fi and/or mobile) in AFWall+ -* if using filtering, NetGuard will _need_ internet access (Wi-Fi and/or mobile) in AFWall+ -* if using filtering, when you un/reinstall NetGuard, remember to re-allow NetGuard in AFWall+ -* if using filtering, applications _need_ VPN internet access (check the box to show that option in AFWall+ settings) - -This question was community contributed. There is no support on using NetGuard and AFWall+ together. - - -**(31) Why can some applications be configured as a group only?** - -For many purposes, including network access, Android groups applications on UID and not on package/application name. -Especially system applications often have the same UID, despite having a different package and application name; these are set up like this by the ROM manufacturer at build time. -These applications can only be allowed/blocked access to the internet as a group. - - -**(32) Why is the battery/network usage of NetGuard so high?** - -This is because Android counts battery and network usage which is normally counted for other applications -against NetGuard in IP filtering mode. The total battery usage is slightly higher when IP filtering mode is enabled. -IP filtering mode is always enabled on Android versions prior to 5.0, and optionally enabled on later Android versions. - - -**(33) Can you add profiles?** - -Profiles are inconvenient because they need to be operated manually. -Conditions like '*When screen is on*' are, on the other hand, convenient because they work automatically. -Therefore profiles will not be added, but you are welcome to propose new conditions; -however, they need to be generally usable to be included. - -As a workaround you can use the export/import function to apply specific settings in specific circumstances. -Alternatively, you can use lockdown mode as a profile. - - -**(34) Can you add a condition 'when on foreground' or 'when active'?** - -Recent Android versions do not allow an application to query if other applications are in the foreground/background or active/inactive -without holding an [additional privacy violating permission](https://developer.android.com/reference/android/Manifest.permission.html#PACKAGE_USAGE_STATS) -and at the expense of extra battery usage (because periodic polling is required). -As a result, this cannot be added without significant disadvantages, like [this one](http://www.xda-developers.com/working-as-intended-an-exploration-into-androids-accessibility-lag/). -You can use the condition '*when screen is on*' instead. - - -**(35) Why does the VPN not start?** - -NetGuard "asks" Android to start the local VPN service, -but some Android versions contain a bug which prevents the VPN from starting (automatically). -Sometimes this is caused by updating NetGuard. -Unfortunately this cannot be fixed by NetGuard. -You can try to restart your device and/or revoke the VPN permissions from NetGuard using the Android settings. -Sometimes it helps to uninstall and install NetGuard again (be sure to export your settings first!). - - -**(36) Can you add PIN or password protection?** - -Since turning off the VPN service using the Android settings cannot be prevented, -there is little use in adding PIN or password protection. - - -**(37) Why are the pro features so expensive?** - -The right question is "*why are there so many taxes and fees*": - -* VAT: 25% (depending on your country) -* Google fee: 30% -* Income tax: 50% - -So, what is left for the developer is just a fraction of what you pay. - -Despite NetGuard being *really* a lot of work, only some of the convenience and advanced features need to be purchased, -which means that NetGuard is basically free to use -and that you don't need to pay anything to reduce your data usage, increase battery life, and increase your privacy. - -Also note that most free applications will appear not to be sustainable in the end, whereas NetGuard is properly maintained and supported, -and that free applications may have a catch, like sending privacy sensitive information to the internet. - -See [here](http://forum.xda-developers.com/showpost.php?p=67892427&postcount=3030) for some more information. - - -**(38) Why did NetGuard stop running?** - -First of all, please make sure you disabled battery optimizations for NetGuard in the Android settings. - -On most devices, NetGuard will keep running in the background with its foreground service. -On some devices (in particular some Samsung models), where there are lots of applications competing for memory, Android may still stop NetGuard as a last resort. -Some Android versions, in particular of Huawei (see [here](https://www.forbes.com/sites/bensin/2016/07/04/push-notifications-not-coming-through-to-your-huawei-phone-heres-how-to-fix-it/) for a fix) or Xiaomi (see [here](https://www.forbes.com/sites/bensin/2016/11/17/how-to-fix-push-notifications-on-xiaomis-miui-8-for-real/) for a fix) stop apps and services too aggressively. -Unfortunately this cannot be fixed by NetGuard, and can be considered a shortcoming of the device and/or as a bug in Android. -As a matter of fact lots of apps suffer from this, see the website [Don't kill my app!](https://dontkillmyapp.com/) for more information and solutions. -You can workaround this problem by enabling the watchdog in the NetGuard advanced options to check every 10-15 minutes. - - -**(39) How does a VPN based firewall differ from a iptables based firewall?** - -See this [Stack Exchange question](http://android.stackexchange.com/questions/152087/any-security-difference-between-root-based-firewall-afwall-and-non-root-based). - - -**(40) Can you add schedules?** - -Besides not being trivial to add, schedules - in my opinion - are not a good idea, since time is not a good rule condition. -A rule condition like *When screen is on* is a better and more straightforward condition. -Therefore schedules will not be added, but you are welcome to propose other new conditions. - - -**(41) Can you add wildcards / address/port ranges?** - -Wildcards to allow/block addresses and address/port ranges would have a significant performance and usability impact and therefore will not be added. -Wildcards rules and address/port ranges would need to be checked for each and every connection attempt. -Since NetGuard blocks, unlike any other no-root firewall, domain names instead of IP addresses there is hardly a need for wildcards. - - -**(42) Why is permission ... needed?** - -* INTERNET ('*Full network access*'): to forward allowed (filtered) traffic to the internet -* ACCESS_NETWORK_STATE ('*View network connections*'): to check if the device is connected to the internet through Wi-Fi -* READ_PHONE_STATE ('*Device ID & call information*'): to detect mobile network changes, see [here](http://forum.xda-developers.com/showpost.php?p=64107371&postcount=489) for more details -* ACCESS_WIFI_STATE ('*Wi-Fi connection information*'): to detect Wi-Fi network changes -* RECEIVE_BOOT_COMPLETED ('*Run at startup*'): to start the firewall when booting the device -* WAKE_LOCK ('*Prevent device from sleeping*'): to reliably reload rules in the background on connectivity changes -* VIBRATE: to provide vibration feedback on widget tap -* FOREGROUND_SERVICE ('foreground service'): to run a foreground service on Android 9 Pie and later -* QUERY_ALL_PACKAGES: to list all apps on Android 11 and later -* BILLING: to use in-app billing - - -**(43) I get 'This app is causing your device to run slowly'** - -This message is displayed by the *Smart Manager*, -but actually it is the 'Smart' Manager application itself which is causing delays and lags. -Some links: - -* [Smart Manager complaining about LastPass](https://www.reddit.com/r/GalaxyS6/comments/3htu2y/smart_manager_cmoplaining_about_lastpass/) -* [Disable Smart Manager?](http://forums.androidcentral.com/samsung-galaxy-s4/595483-disable-smart-manager.html) - - -**(44) I don't get notifications on access** - -To prevent a high number of status bar notifications, notify on access is done only once per domain name per application. -Access to domain names shown in the application access log (drill down in the NetGuard application settings) will not be notified again, -even if you just enabled notify on access. -To get notified for all domain names again, you can clear the application access log using the trashcan icon. -If you want to clear all applications logs, you can export and import your settings. - -Another reason why you don't get notifications could be an applied "Power Saving Mode" for example on Samsung devices. Even if you do not restrict CPU frequency in this mode. - - -**(45) Does NetGuard handle incoming connections?** - -The Android VPN service handles outgoing connections only (from applications to the internet), so incoming connections are normally left alone. - -If you want to run a server application on Android, then be aware that using port numbers below 1024 require root permissions -and that some Android versions contain routing bugs, causing inbound traffic incorrectly being routed into the VPN. - - -**(46) Can I get a refund?** - -If a purchased pro feature doesn't work [as described](https://www.netguard.me/) -and this isn't caused by a problem in the free features -and I cannot fix the problem in a timely manner, you can get a refund. -In all other cases there is no refund possible. -In no circumstances there can be a refund for any problem related to the free features, -since there wasn't paid anything for them and because they can be evaluated without any limitation. -I take my responsibility as seller to deliver what has been promised -and I expect that you take responsibility for informing yourself of what you are buying. - - -**(48) Why are some domain names blocked while they are set to be allowed?** - -NetGuard blocks traffic based on the IP addresses an application is trying to connect to. -If more than one domain name is on the same IP, they cannot be distinguished. -If you set different rules for 2 domains which resolve to the same IP, both will be blocked. - -Thanks @[pulser](https://github.com/pulser/) - -Another potential problem is that Android doesn't honor the DNS TTL value and applies its own caching rules. -This could result in NetGuard too early or too late purging a DNS record from its own cache, -resulting in not recognizing an IP address or recognizing a wrong IP address. -You can try to workaround this by changing the DNS TTL value setting of NetGuard. -This value is used as a minimum DNS TTL value in an attempt to mimick the behavior of Android. - -NetGuard will also block traffic while restarting the Android VPN service to apply new rules, -for example when connectivity changes or when the screen is turned on or off. - - -**(49) Does NetGuard encrypt my internet traffic / hide my IP address?** - -NetGuard is a firewall application that filters internet traffic on your device (see also [this question](#user-content-faq6)), -so it is not meant to - and does not - encrypt your internet traffic or hide your IP address. - - -**(50) Will NetGuard automatically start on boot?** - -Yes, NetGuard will automatically be started on boot if you powered off your device with NetGuard enabled and NetGuard is not installed on external storage. - -Some devices, for example OnePlus and Mi devices, can prevent certain apps from auto-starting after reboot. -This can be disabled in the Android settings. - - -**(51) Why does NetGuard block all internet traffic?!** - -Make sure you have put NetGuard on the doze exception list (Android 6 Marshmallow or later) -and that Android allows NetGuard to use the internet in the background (see also [this question](#user-content-faq21)). - -Make sure you are not running NetGuard in allow (whitelist) mode (check the NetGuard default settings). - -Make sure you didn't enable the Always-On VPN sub option '*Block connections without VPN*' (Android 8 Oreo or later). -This will block resolving domain names too (is it a bug or feature?). - -Some internet providers block all DNS requests except via their own DNS servers. -So, if you configured custom DNS servers, try to undo this. - -Some Android versions, including LineageOS and /e/ for some devices, contain a bug resulting in all internet traffic being blocked. -Mostly, you can workaround this bug by enabling filtering in NetGuard's *Advanced options*. -If this doesn't solve the issue, the problem can unfortunately not be fixed or worked around by NetGuard. -Please [see here](https://forum.xda-developers.com/t/app-6-0-netguard-no-root-firewall.3233012/post-84457527) for a fix. - - -**(52) What is lockdown mode?** - -In lockdown mode, all traffic for all applictions will be blocked, -except for applications with the condition *'Allow in lockdown mode'* enabled. -You can use this mode to limit battery usage or network usage, -for example, when your battery is almost empty or when your data allotment is almost exhausted. - -Note that Lockdown mode applies only if the corresponding option is also set in "Network options" -(one for Wi-Fi mode, one for Mobile data), allowing to have lockdown in only one of the two network modes -and not in the other (eg. Lock down if mobile data are active, but not if Wi-Fi is currently used). - -Note also that system applications will only be blocked in this mode -when managing system applications is enabled in the advanced settings. - -You can enable/disable lockdown mode in the main menu, using a widget, or using a settings tile (Android 7 Nougat or later). - - -**(53) The translation in my language is missing / incorrect / incomplete** - -You can contribute translations [here](https://crowdin.com/project/netguard) (registration is free). -If your language is missing, please contact me to have it added. - - -**(54) How to tunnel all TCP connections through the Tor network?** - -Tor with NetGuard is only supported in the [XDA NetGuard forum](http://forum.xda-developers.com/showthread.php?t=3233012). -There is no personal support on Tor with NetGuard, because I don't use Tor myself. - -First, install [Orbot](market://details?id=org.torproject.android), the Android client for Tor, -run it, press _Start_, while it connects open its _Settings_ and make sure it's setup to auto-start -on device start. - -In NetGuard's _Network options_ enable _Subnet routing_ and in _Advanced options_ toggle on -_Use SOCKS5 proxy_ with address 127.0.0.1 and port as 9050 (this is the default port, if you changed -this in Orbot make the adjustment here also). - -This should be enough, if testing fails (eg. no connection at all) you can open the app details -for Orbot, uncheck _Apply rules and conditions_ and retry. - -How to test: open Firefox (or another non-proxy enabled browser) to the address https://ipleak.net/ -and you should see a different IP address from your regular one, and below in the _Tor Exit Node_ -field something else besides _Unknown_. - -**Be aware** that all the other Tor caveats (https://www.torproject.org/docs/faq.html.en) still apply, -like having the Tor network unreacheable, your activity actively monitored/targeted in your country, -online services (eg. Gmail, Google Play store) failing to login or being forced to solve endless capchas -when accessing sites that use Cloudflare's CDN services. - - -**(55) Why does NetGuard connect to Amazon / ipinfo.io / 216.239.34.21?** - -NetGuard connects to Amazon / [ipinfo.io](https://ipinfo.io/) to show the names and organizations for IP addresses. -If you don't want this, just disable showing names and organizations using the three dot menu in the global log view. - - -**(56) Why does NetGuard allow all internet traffic?!** - -NetGuard can block each and every application, even system applications and components. - -NetGuard, by default, allows all traffic to prevent hard to find problems. You need to selectively block traffic yourself by tapping on the mobile or Wi-Fi icons. - -Be aware that NetGuard will allow traffic to an application when the screen is on and the condition *'when screen on'* is enabled. - - -**(57) Why does NetGuard use so much data?** - -Basically, NetGuard doesn't use data itself. -However, many Android versions incorrectly account data of other applications flowing through NetGuard to NetGuard instead of to the applications. -The data usage of other applications will be zero with NetGuard enabled in this case. - -The total data usage of your device will be the same with and without NetGuard. - - -**(58) Why does loading the application list take a long time?** - -The application list is provided by Android, so the loading speed depends mostly on the power of your device and on the efficiency of your Android version. -For example shortage of memory could lead to increased loading times, because memory needs to be freed, for example by pausing other applications. - -In some circumstances, restricting system apps and system components is known to cause the application list to load slowly or not at all. The exact circumstances are unknown. - - -**(59) Can you help me restore my purchase?** - -Google manages all purchases, so as a developer I have no control over purchases. -So, the only thing I can do, is give some advice: - -* Make sure you have an active internet connection -* Make sure you didn't block Google Play store / Play services -* Make sure you are logged in with the right Google account and that there is nothing wrong with your Google account -* Make sure you installed NetGuard via the right Google account if you configured multiple Google accounts on your device -* Open the Play store app and wait at least a minute to give it time to synchronize with the Google servers -* Open NetGuard and navigate to the pro features screen; NetGuard will check the purchases again - -You can also try to clear the cache of the Play store app via the Android apps settings. - -Note that: - -* Purchases are stored in the Google cloud and cannot get lost -* There is no time limit on purchases, so they cannot expire -* Google does not expose details (name, e-mail, etc) about buyers to developers -* An app like NetGuard cannot select which Google account to use -* It may take a while until the Play store app has synchronized a purchase to another device -* Play Store purchases cannot be used without the Play Store, which is also not allowed by Play Store rules - -If you cannot solve the problem with the purchase, you will have to contact Google about it. - - -**(60) Why does IP (Wi-Fi) calling/SMS/MMS not work?** - -Please see the [compatibility section](https://github.com/M66B/NetGuard/#compatibility) about this -(you might need to request the desktop version to see this section if you are using a mobile device). - - -**(61) Help, NetGuard crashed!** - -NetGuard rarely crashes ("unexpectedly stopped"), but if it crashed (which is something different than being stopped by Android, see [this FAQ](#user-content-faq38)), -then it is mostly caused by bugs in your Android version -(either in the [Android VPN service](https://developer.android.com/reference/android/net/VpnService.html) implementation or in the [Android Linux kernel](https://developer.android.com/guide/platform/index.html#linux-kernel)). -I am happy to check what the cause of a crash is and I will fix it whenever possible, but I need a logcat captured from your PC with the crash log for this. -Since logcats are mostly quite large, I will need the exact time of the crash as well. -If you don't know how to capture a logcat from your PC, please use your favorite search engine to find one of the numerous guides. - - -**(62) How can I solve 'There was a problem parsing the package' ?** - -Likely causes are that the downloaded APK file is damaged (which could be caused by a virus scanner) -or that you are trying to install NetGuard on a not supported Android version. - - -**(63) Why is all DNS traffic allowed?** - -NetGuard blocks unlike any other Android firewall on real domain names. -For this a list of domain names and IP address needs to be built. -For this purpose, NetGuard allows all DNS traffic, even if the domain name is listed in the hosts file. -However, this doesn't mean traffic to the resolved IP address is allowed. - -If you don't trust the system (Google's) or your provider's DNS servers, you can set alternative DNS servers in the advanced settings. -Be sure to enter and confirm the addresses and to set two DNS server addresses. -If you enter just one DNS server address, it will be used in addition to the default DNS server addresses. - - -**(64) Can you add DNS over TLS/HTTP?** - -If you mean to intercept [DNS over HTTP](https://en.wikipedia.org/wiki/DNS_over_HTTPS) (DoH) -or [DNS over TLS](https://en.wikipedia.org/wiki/DNS_over_TLS) (DoT) requests to resolve domain names, -this is not possible because DoH/DoT traffic is encrypted, which is the whole point of DoH/DoT. - -Please [see here](https://github.com/Ch4t4r/Nebulo/blob/master/docs/NONVPNMODE.md) about how you can use DoH/DoT with NetGuard anyway. - -
- - -**(65) Why can NetGuard not block itself?** - -First of all, if NetGuard could block itself, you should trust that NetGuard really blocks itself, -which is basically the same as trusting that NetGuard doesn't connect to the internet when not needed. - -Note that NetGuard needs to connect to the internet to forward traffic of other apps to the internet and to lookup information on IP addresses, -see also [this FAQ](#user-content-faq55). - -NetGuard could block itself in older versions, -but this required calling [VpnService.protect](https://developer.android.com/reference/android/net/VpnService.html#protect(int)) for each and every connection. -Since there are lots of connections of lots of apps in a typical Android environment, -this resulted in wasting battery power and in crashes on some Android versions with bugs in this function. - -So, because blocking NetGuard with itself didn't added anything useful -and to save on battery power and to prevent crashes blocking NetGuard with itself was removed. - -
- - -**(66) Why is a blocked app still accessing the internet?** - -Blocked apps cannot access the internet. There are no exceptions to this. -All app and system traffic flows through the [Android VPN service](https://developer.android.com/guide/topics/connectivity/vpn), -which is a *must* for companies with high security requirements. -This also means that all apps will be treated in the same way -and that the global access log (*Show log* in the three-dots overflow menu) will show all traffic. - -However: - -* Apps can show locally cached content -* Incoming (push) messages are received by the system component Google Play services and not apps, especially when the app is in the background or when the screen is turned off -* Similarly, advertisements are mostly received by the system component Google Play services -* Downloads are often performed by the download manager and not apps - -If you like to block Google Play services or the download manager, you'll need to enable managing system apps in the advanced settings. - -If you like to make sure that push messages will always be received, you can disable *Apply rules and conditions* for Google Play services. - -To be clear: in most cases **you cannot block ads by blocking apps**. -However, you can block ads for all apps with NetGuard, please see [here](https://github.com/M66B/NetGuard/blob/master/ADBLOCKING.md) about how to. - -
- - -**(67) Who is 'nobody'?** - -["nobody" is the conventional name of a user account](https://en.wikipedia.org/wiki/Nobody_(username)) -which owns no files, is in no privileged groups, and has no abilities except those which every other user has. - -
- -**NetGuard is supported for phones and tablets only, so not for other device types like televisions or vehicles.** - -**If you didn't find the answer to your question, you can ask your questions [in this forum](http://forum.xda-developers.com/showthread.php?t=3233012) or contact me by using [this contact form](https://contact.faircode.eu/)**. diff --git a/NetworkGenie/FUNDING.yml b/NetworkGenie/FUNDING.yml deleted file mode 100644 index 6fea02d..0000000 --- a/NetworkGenie/FUNDING.yml +++ /dev/null @@ -1 +0,0 @@ -github: [M66B] diff --git a/NetworkGenie/LICENSE b/NetworkGenie/LICENSE deleted file mode 100644 index 733c072..0000000 --- a/NetworkGenie/LICENSE +++ /dev/null @@ -1,675 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - {one line to give the program's name and a brief idea of what it does.} - Copyright (C) {year} {name of author} - - This program 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. - - This program 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 this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - {project} Copyright (C) {year} {fullname} - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. - diff --git a/NetworkGenie/README.md b/NetworkGenie/README.md deleted file mode 100644 index e4a18db..0000000 --- a/NetworkGenie/README.md +++ /dev/null @@ -1,388 +0,0 @@ -# NetGuard - -*NetGuard* provides simple and advanced ways to block access to the internet - no root required. -Applications and addresses can individually be allowed or denied access to your Wi-Fi and/or mobile connection. - -
- -**WARNING: there is an app in the Samsung Galaxy app store "*Play Music - MP3 Music player*" -with the same package name as NetGuard, which will be installed as update without your confirmation. -This app is probably malicious and was reported to Samsung on December 8, 2021.** - -
- -Blocking access to the internet can help: - -* reduce your data usage -* save your battery -* increase your privacy - -NetGuard is the first free and open source no-root firewall for Android. - -Features: - -* Simple to use -* No root required -* 100% open source -* No calling home -* No tracking or analytics -* Actively developed and supported -* Android 5.1 and later supported -* IPv4/IPv6 TCP/UDP supported -* Tethering supported -* Optionally allow when screen on -* Optionally block when roaming -* Optionally block system applications -* Optionally forward ports, also to external addresses (not available if installed from the Play store) -* Optionally notify when an application accesses the internet -* Optionally record network usage per application per address -* Optionally [block ads using a hosts file](https://github.com/M66B/NetGuard/blob/master/ADBLOCKING.md) (not available if installed from the Play store) -* Material design theme with light and dark theme - -PRO features: - -* Log all outgoing traffic; search and filter access attempts; export PCAP files to analyze traffic -* Allow/block individual addresses per application -* New application notifications; configure NetGuard directly from the notification -* Display network speed graph in a status bar notification -* Select from five additional themes in both light and dark version - -There is no other no-root firewall offering all these features. - -Requirements: - -* Android 5.1 or later -* A [compatible device](#compatibility) - -Downloads: - -* [GitHub](https://github.com/M66B/NetGuard/releases) -* [Google Play](https://play.google.com/store/apps/details?id=eu.faircode.netguard) - -Certificate fingerprints: - -* MD5: B6:4A:E8:08:1C:3C:9C:19:D6:9E:29:00:46:89:DA:73 -* SHA1: EF:46:F8:13:D2:C8:A0:64:D7:2C:93:6B:9B:96:D1:CC:CC:98:93:78 -* SHA256: E4:A2:60:A2:DC:E7:B7:AF:23:EE:91:9C:48:9E:15:FD:01:02:B9:3F:9E:7C:9D:82:B0:9C:0B:39:50:00:E4:D4 - -Usage: - -* Enable the firewall using the switch in the action bar -* Allow/deny Wi-Fi/mobile internet access using the icons along the right side of the application list - -You can use the settings menu to change from blacklist mode (allow all in *Settings* but block unwanted applications in list) to whitelist mode (block all in *Settings* but allow favorite applications in list). - -* Red/orange/yellow/amber = internet access denied -* Teal/blue/purple/grey = internet access allowed - - - - - - -For more screenshots, see [here](https://github.com/M66B/NetGuard/tree/master/screenshots). - -Compatibility -------------- - -The only way to build a no-root firewall on Android is to use the Android VPN service. -Android doesn't allow chaining of VPN services, so you cannot use NetGuard together with other VPN based applications. -See also [this FAQ](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq2). - -NetGuard can be used on rooted devices too and even offers more features than most root firewalls. - -Some older Android versions, especially Samsung's Android versions, have a buggy VPN implementation, -which results in Android refusing to start the VPN service in certain circumstances, -like when there is no internet connectivity yet (when starting up your device) -or when incorrectly requiring manual approval of the VPN service again (when starting up your device). -NetGuard will try to workaround this and remove the error message when it succeeds, else you are out of luck. - -Some LineageOS versions have a broken Android VPN implementation, causing all traffic to be blocked, -please see [this FAQ](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq51) for more information. - -NetGuard is not supported for apps installed in a [work profile](https://developer.android.com/work/managed-profiles), -or in a [Secure Folder](https://www.samsung.com/uk/support/mobile-devices/what-is-the-secure-folder-and-how-do-i-use-it/) (Samsung), -or as second instance (MIUI), or as Parallel app (OnePlus), or as Xiaomi dual app -because the Android VPN service too often does not work correctly in this situation, which can't be fixed by NetGuard. - -Filtering mode cannot be used on [CopperheadOS](https://copperhead.co/android/). - -NetGuard will not work or crash when the package *com.android.vpndialogs* has been removed or otherwise is unavailable. -Removing this package is possible with root permissions only. -If you disable this package, you can enable it with this command again: - -``` -adb shell pm enable --user 0 com.android.vpndialogs -``` - -NetGuard is supported for phones and tablets only, so not for other device types like on a television or in a car. - -Android does not allow incoming connections (not the same as incoming traffic) and the Android VPN service has no support for this either. -Therefore managing incoming connections for servers running on your device is not supported. - -Wi-Fi or IP calling will not work if your provider uses [IPsec](https://en.wikipedia.org/wiki/IPsec) to encrypt your phone calls, SMS messages and/or MMS messages, -unless there was made an exception in NetGuard for your provider (currently for T-Mobile and Verizon). -I am happy to add exceptions for other providers, but I need the [MCC](https://en.wikipedia.org/wiki/Mobile_country_code) codes, [MNC](https://en.wikipedia.org/wiki/MNC) codes and [IP address](https://en.wikipedia.org/wiki/IP_address) ranges your provider is using. -As an alternative you can enable the option '*Disable on call*', which is available since version 2.113. - - - -Frequently Asked Questions (FAQ) --------------------------------- - - -[**(0) How do I use NetGuard?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq0) - - -[**(1) Can NetGuard completely protect my privacy?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq1) - - -[**(2) Can I use another VPN application while using NetGuard?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq2) - - -[**(3) Can I use NetGuard on any Android version?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq3) - - -[**(4) Will NetGuard use extra battery power?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq4) - - -[**(6) Will NetGuard send my internet traffic to an external (VPN) server?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq6) - - -[**(7) Why are applications without internet permission shown?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq7) - - -[**(8) What do I need to enable for the Google Play™ store app to work?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq8) - - -[**(9) Why is the VPN service being restarted?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq9) - - -[**(10) Will you provide a Tasker plug-in?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq10) - - -[**(13) How can I remove the ongoing NetGuard entry in the notification screen?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq13) - - -[**(14) Why can't I select OK to approve the VPN connection request?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq14) - - -[**(15) Are F-Droid builds supported?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq15) - - -[**(16) Why are some applications shown dimmed?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq16) - - -[**(17) Why is NetGuard using so much memory?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq17) - - -[**(18) Why can't I find NetGuard in the Google Play™ store app?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq18) - - -[**(19) Why does application XYZ still have internet access?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq19) - - -[**(20) Can I Greenify/hibernate NetGuard?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq20) - - -[**(21) Does doze mode affect NetGuard?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq21) - - -[**(22) Can I tether (use the Android hotspot) / use Wi-Fi calling while using NetGuard?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq22) - - -[**(24) Can you remove the notification from the status bar?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq24) - - -[**(25) Can you add a 'select all'?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq25) - - -[**(27) How do I read the blocked traffic log?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq27) - - -[**(28) Why is Google connectivity services allowed internet access by default?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq28) - - -[**(29) Why do I get 'The item you requested is not available for purchase'?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq29) - - -[**(30) Can I also run AFWall+ on the same device?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq30) - - -[**(31) Why can some applications be configured as a group only?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq31) - - -[**(32) Why is the battery/network usage of NetGuard so high**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq32) - - -[**(33) Can you add profiles?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq33) - - -[**(34) Can you add the condition 'when on foreground'?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq34) - - -[**(35) Why does the VPN not start?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq35) - - -[**(36) Can you add PIN or password protection?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq36) - - -[**(37) Why are the pro features so expensive?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq37) - - -[**(38) Why did NetGuard stop running?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq38) - - -[**(39) How does a VPN based firewall differ from a iptables based firewall?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq39) - - -[**(40) Can you add schedules?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq40) - - -[**(41) Can you add wildcards?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq41) - - -[**(42) Why is permission ... needed?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq42) - - -[**(43) I get 'This app is causing your device to run slowly'**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq43) - - -[**(44) I don't get notifications on access**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq44) - - -[**(45) Does NetGuard handle incoming connections?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq45) - - -[**(46) Can I get a refund?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq46) - - -[**(47) Why are there in application advertisements?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq47) - - -[**(48) Why are some domain names blocked while they are set to be allowed?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq48) - - -[**(49) Does NetGuard encrypt my internet traffic / hide my IP address?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq49) - - -[**(50) Will NetGuard automatically start on boot?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq50) - - -[**(51) NetGuard blocks all internet traffic!**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq51) - - -[**(52) What is lockdown mode?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq52) - - -[**(53) The translation in my language is missing / incorrect / incomplete!**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq53) - - -[**(54) How to tunnel all TCP connections through the Tor network?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq54) - - -[**(55) Why does NetGuard connect to Amazon / ipinfo.io?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq55) - - -[**(56) NetGuard allows all internet traffic!**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq56) - - -[**(57) Why does NetGuard use so much data?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq57) - - -[**(58) Why does loading the application list take a long time?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq58) - - -[**(59) Can you help me restore my purchase?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq59) - - -[**(60) Why does IP (Wi-Fi) calling/SMS/MMS not work?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq60) - - -[**(61) Help, NetGuard crashed!**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq61) - - -[**(62) How can I solve 'There was a problem parsing the package' ?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq62) - - -[**(63) Why is all DNS traffic allowed?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq63) - - -[**(64) Can you add DNS over TLS?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq64) - - -[**(65) Why can NetGuard not block itself?**](https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq65) - -Support -------- - -For questions, feature requests and bug reports, please [use this XDA-Developers forum thread](http://forum.xda-developers.com/showthread.php?t=3233012). - -There is support on the latest version of NetGuard only. - -There is no support on things that are not directly related to NetGuard. - -There is no support on building and developing things by yourself. - -**NetGuard is supported for phones and tablets only, so not for other device types like on a television or in a car.** - -Contributing ------------- - -*Building* - -Building is simple, if you install the right tools: - -* [Android Studio](http://developer.android.com/sdk/) -* [Android NDK](http://developer.android.com/tools/sdk/ndk/) - -The native code is built as part of the Android Studio project. - -It is expected that you can solve build problems yourself, so there is no support on building. -If you cannot build yourself, there are prebuilt versions of NetGuard available [here](https://github.com/M66B/NetGuard/releases). - -*Translating* - -* Translations to other languages are welcomed -* You can translate online [here](https://crowdin.com/project/netguard/) -* If your language is not listed, please send a message to marcel(plus)netguard(at)faircode(dot)eu -* You can see the status of all translations [here](https://crowdin.com/project/netguard). - -Please note that by contributing you agree to the license below, including the copyright, without any additional terms or conditions. - -Attribution ------------ - -NetGuard uses: - -* [Glide](https://bumptech.github.io/glide/) -* [Android Support Library](https://developer.android.com/tools/support-library/) - -License -------- - -[GNU General Public License version 3](http://www.gnu.org/licenses/gpl.txt) - -Copyright (c) 2015-2018 Marcel Bokhorst ([M66B](https://contact.faircode.eu/)) - -All rights reserved - -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 discretion) 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/](http://www.gnu.org/licenses/). - -Trademarks ----------- - -*Android is a trademark of Google Inc. Google Play is a trademark of Google Inc* diff --git a/NetworkGenie/app/.gitignore b/NetworkGenie/app/.gitignore deleted file mode 100644 index 796b96d..0000000 --- a/NetworkGenie/app/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/NetworkGenie/app/CMakeLists.txt b/NetworkGenie/app/CMakeLists.txt deleted file mode 100644 index 65850ff..0000000 --- a/NetworkGenie/app/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ - -cmake_minimum_required(VERSION 3.4.1) - -add_library( netguard - SHARED - src/main/jni/netguard/netguard.c - src/main/jni/netguard/session.c - src/main/jni/netguard/ip.c - src/main/jni/netguard/tcp.c - src/main/jni/netguard/udp.c - src/main/jni/netguard/icmp.c - src/main/jni/netguard/dns.c - src/main/jni/netguard/dhcp.c - src/main/jni/netguard/pcap.c - src/main/jni/netguard/debug_conn.c - src/main/jni/netguard/util.c ) - -include_directories( src/main/jni/netguard/ ) - -find_library( log-lib - log ) - -target_link_libraries( netguard - ${log-lib} ) diff --git a/NetworkGenie/app/build.gradle b/NetworkGenie/app/build.gradle index 9eddc14..3142938 100644 --- a/NetworkGenie/app/build.gradle +++ b/NetworkGenie/app/build.gradle @@ -1,107 +1,91 @@ apply plugin: 'com.android.application' -//def keystorePropertiesFile = rootProject.file("keystore.properties") -//def keystoreProperties = new Properties() -//keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) android { - compileSdkVersion = 31 + namespace 'com.breakpointingbad.networkgenie' + compileSdk 34 defaultConfig { - applicationId = "eu.faircode.netguard" - versionName = "2.303" - minSdkVersion 22 - targetSdkVersion 31 - versionCode = 2022111001 - archivesBaseName = "NetGuard-v$versionName" + applicationId "com.breakpointingbad.networkgenie" + minSdk 24 + targetSdk 34 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { - cppFlags "" - arguments "-DANDROID_PLATFORM=android-22" - // https://developer.android.com/ndk/guides/cmake.html + cppFlags '' } } - //ndkVersion "21.4.7075529" - ndk { - // https://developer.android.com/ndk/guides/abis.html#sa - abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' - } - } - signingConfigs { - release { - //storeFile file(keystoreProperties['storeFile']) - //storePassword keystoreProperties['storePassword'] - //keyAlias keystoreProperties['keyAlias'] - //keyPassword keystoreProperties['keyPassword'] - storeFile file("my.keystore") - storePassword "store_password" - keyAlias "my_key_alias" - keyPassword "key_password" - - } - } - - externalNativeBuild { - cmake { - path "CMakeLists.txt" - } } buildTypes { release { - minifyEnabled = true - //proguardFiles.add(file('proguard-rules.pro')) - signingConfig signingConfigs.release + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + buildConfigField "boolean", "PLAY_STORE_RELEASE", "false" buildConfigField "String", "HOSTS_FILE_URI", "\"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts\"" - buildConfigField "String", "GITHUB_LATEST_API", "\"https://api.github.com/repos/M66B/NetGuard/releases/latest\"" - } - play { - minifyEnabled = true - signingConfig signingConfigs.release - //proguardFiles.add(file('proguard-rules.pro')) - buildConfigField "boolean", "PLAY_STORE_RELEASE", "true" - buildConfigField "String", "HOSTS_FILE_URI", "\"\"" - buildConfigField "String", "GITHUB_LATEST_API", "\"\"" + buildConfigField "String", "GITHUB_LATEST_API", "\"https://github.com/beaukuj15/NetworkGenie\"" + } + debug { - minifyEnabled = true - proguardFiles.add(file('proguard-rules.pro')) + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + buildConfigField "boolean", "PLAY_STORE_RELEASE", "false" buildConfigField "String", "HOSTS_FILE_URI", "\"https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts\"" - buildConfigField "String", "GITHUB_LATEST_API", "\"https://api.github.com/repos/M66B/NetGuard/releases/latest\"" + buildConfigField "String", "GITHUB_LATEST_API", "\"https://github.com/beaukuj15/NetworkGenie\"" + } } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + externalNativeBuild { + cmake { + path file('src/main/cpp/CMakeLists.txt') + version '3.22.1' + } } lint { disable 'MissingTranslation' } + namespace 'com.breakpointingbad.networkgenie' + buildFeatures { + aidl true + } } dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) - // https://developer.android.com/jetpack/androidx/releases/ - implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' - implementation 'androidx.recyclerview:recyclerview:1.2.1' - implementation 'androidx.preference:preference:1.1.1' - implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' - implementation 'com.google.android.material:material:1.4.0' - implementation 'androidx.constraintlayout:constraintlayout:2.1.4' - annotationProcessor 'androidx.annotation:annotation:1.2.0' + implementation 'androidx.recyclerview:recyclerview:1.3.1' + implementation 'androidx.preference:preference:1.2.1' + implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0' + annotationProcessor 'androidx.annotation:annotation:1.7.0' // https://bumptech.github.io/glide/ - implementation('com.github.bumptech.glide:glide:4.11.0') { + implementation('com.github.bumptech.glide:glide:4.14.2') { exclude group: "com.android.support" } - annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' -} + annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2' + + implementation libs.material + implementation libs.activity + implementation libs.constraintlayout + implementation libs.junit + androidTestImplementation libs.ext.junit + androidTestImplementation libs.espresso.core + + +} \ No newline at end of file diff --git a/NetworkGenie/app/proguard-rules.pro b/NetworkGenie/app/proguard-rules.pro index 2c3886d..481bb43 100644 --- a/NetworkGenie/app/proguard-rules.pro +++ b/NetworkGenie/app/proguard-rules.pro @@ -1,14 +1,10 @@ # Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /home/marcel/Android/Sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html -# Add any project specific keep options here: - # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: @@ -16,47 +12,10 @@ # public *; #} -#Line numbers --renamesourcefileattribute SourceFile --keepattributes SourceFile,LineNumberTable - -#NetGuard --keepnames class eu.faircode.netguard.** { *; } - -#JNI --keepclasseswithmembernames class * { - native ; -} - -#JNI callbacks --keep class eu.faircode.netguard.Allowed { *; } --keep class eu.faircode.netguard.Packet { *; } --keep class eu.faircode.netguard.ResourceRecord { *; } --keep class eu.faircode.netguard.Usage { *; } --keep class eu.faircode.netguard.ServiceSinkhole { - void nativeExit(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); - int getUidQ(int, int, java.lang.String, int, java.lang.String, int); - eu.faircode.netguard.Allowed getRomAction(eu.faircode.netguard.Packet); - void accountUsage(eu.faircode.netguard.Usage); -} - -#AndroidX --keep class androidx.appcompat.widget.** { *; } --keep class androidx.appcompat.app.AppCompatViewInflater { (...); } --keepclassmembers class * implements android.os.Parcelable { static ** CREATOR; } - -#Glide --keep public class * implements com.bumptech.glide.module.GlideModule --keep public class * extends com.bumptech.glide.module.AppGlideModule --keep enum com.bumptech.glide.** {*;} -#-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** { -# **[] $VALUES; -# public *; -#} +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable -#AdMob --dontwarn com.google.android.gms.internal.** +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/NetworkGenie/app/src/androidTest/java/com/breakpointingbad/networkgenie/ExampleInstrumentedTest.java b/NetworkGenie/app/src/androidTest/java/com/breakpointingbad/networkgenie/ExampleInstrumentedTest.java new file mode 100644 index 0000000..173ce83 --- /dev/null +++ b/NetworkGenie/app/src/androidTest/java/com/breakpointingbad/networkgenie/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.breakpointingbad.networkgenie; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.breakpointingbad.networkgenie", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/NetworkGenie/app/src/main/AndroidManifest.xml b/NetworkGenie/app/src/main/AndroidManifest.xml index ce3faee..585a8c8 100644 --- a/NetworkGenie/app/src/main/AndroidManifest.xml +++ b/NetworkGenie/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ @@ -12,25 +11,32 @@ - - + + + + + + + + + - - + + - + android:required="false" /> android:supportsRtl="true" android:theme="@style/AppThemeTeal" tools:ignore="ManifestResource"> - + + android:resizeableActivity="true"> - - - + + - @@ -119,6 +122,7 @@ queries> android:name="android.support.PARENT_ACTIVITY" android:value=".ActivityMain" /> + android:name="android.support.PARENT_ACTIVITY" android:value=".ActivityMain" /> + android:name="android.support.PARENT_ACTIVITY" android:value=".ActivityMain" /> + android:name="android.support.PARENT_ACTIVITY" android:value=".ActivitySettings" /> + android:name="android.support.PARENT_ACTIVITY" android:value=".ActivitySettings" /> + android:label="@string/app_name" android:theme="@style/AppDialog"> - - + + + - + + + + + + - + - + - + + android:permission="com.breakpointingbad.com.permission.ADMIN"> - - - - + + + + - - \ No newline at end of file + diff --git a/NetworkGenie/app/src/main/assets/rom1.txt b/NetworkGenie/app/src/main/assets/rom1.txt deleted file mode 100644 index 7dd7e4b..0000000 --- a/NetworkGenie/app/src/main/assets/rom1.txt +++ /dev/null @@ -1 +0,0 @@ -some rom info here.. diff --git a/NetworkGenie/app/src/main/cpp/.networkgenie.c.swp b/NetworkGenie/app/src/main/cpp/.networkgenie.c.swp new file mode 100644 index 0000000..02b8518 Binary files /dev/null and b/NetworkGenie/app/src/main/cpp/.networkgenie.c.swp differ diff --git a/NetworkGenie/app/src/main/cpp/CMakeLists.txt b/NetworkGenie/app/src/main/cpp/CMakeLists.txt new file mode 100644 index 0000000..34924cf --- /dev/null +++ b/NetworkGenie/app/src/main/cpp/CMakeLists.txt @@ -0,0 +1,16 @@ + +cmake_minimum_required(VERSION 3.4.1) + +add_library( networkgenie + SHARED + + networkgenie.cpp networkgenie.c session.c ip.c tcp.c udp.c + tls.c icmp.c dns.c dhcp.c pcap.c util.c debug_conn.c) + +include_directories( src/main/cpp/ ) + +find_library( log-lib + log ) + +target_link_libraries( networkgenie + ${log-lib} ) diff --git a/NetworkGenie/app/src/main/jni/netguard/debug_conn.c b/NetworkGenie/app/src/main/cpp/comp/debug_conn.c similarity index 100% rename from NetworkGenie/app/src/main/jni/netguard/debug_conn.c rename to NetworkGenie/app/src/main/cpp/comp/debug_conn.c diff --git a/NetworkGenie/app/src/main/jni/netguard/dhcp.c b/NetworkGenie/app/src/main/cpp/comp/dhcp.c similarity index 100% rename from NetworkGenie/app/src/main/jni/netguard/dhcp.c rename to NetworkGenie/app/src/main/cpp/comp/dhcp.c diff --git a/NetworkGenie/app/src/main/jni/netguard/dns.c b/NetworkGenie/app/src/main/cpp/comp/dns.c similarity index 100% rename from NetworkGenie/app/src/main/jni/netguard/dns.c rename to NetworkGenie/app/src/main/cpp/comp/dns.c diff --git a/NetworkGenie/app/src/main/jni/netguard/icmp.c b/NetworkGenie/app/src/main/cpp/comp/icmp.c similarity index 100% rename from NetworkGenie/app/src/main/jni/netguard/icmp.c rename to NetworkGenie/app/src/main/cpp/comp/icmp.c diff --git a/NetworkGenie/app/src/main/jni/netguard/ip.c b/NetworkGenie/app/src/main/cpp/comp/ip.c similarity index 100% rename from NetworkGenie/app/src/main/jni/netguard/ip.c rename to NetworkGenie/app/src/main/cpp/comp/ip.c diff --git a/NetworkGenie/app/src/main/jni/netguard/netguard.c b/NetworkGenie/app/src/main/cpp/comp/netguard.c similarity index 99% rename from NetworkGenie/app/src/main/jni/netguard/netguard.c rename to NetworkGenie/app/src/main/cpp/comp/netguard.c index fc5c637..f088190 100644 --- a/NetworkGenie/app/src/main/jni/netguard/netguard.c +++ b/NetworkGenie/app/src/main/cpp/comp/netguard.c @@ -1127,4 +1127,4 @@ Java_eu_faircode_netguard_Util_dump_1memory_1profile(JNIEnv *env, jclass type) { log_android(ANDROID_LOG_ERROR, "pthread_mutex_unlock failed"); #endif -} \ No newline at end of file +} diff --git a/NetworkGenie/app/src/main/jni/netguard/netguard.h b/NetworkGenie/app/src/main/cpp/comp/netguard.h similarity index 100% rename from NetworkGenie/app/src/main/jni/netguard/netguard.h rename to NetworkGenie/app/src/main/cpp/comp/netguard.h diff --git a/NetworkGenie/app/src/main/jni/netguard/pcap.c b/NetworkGenie/app/src/main/cpp/comp/pcap.c similarity index 100% rename from NetworkGenie/app/src/main/jni/netguard/pcap.c rename to NetworkGenie/app/src/main/cpp/comp/pcap.c diff --git a/NetworkGenie/app/src/main/jni/netguard/session.c b/NetworkGenie/app/src/main/cpp/comp/session.c similarity index 100% rename from NetworkGenie/app/src/main/jni/netguard/session.c rename to NetworkGenie/app/src/main/cpp/comp/session.c diff --git a/NetworkGenie/app/src/main/jni/netguard/tcp.c b/NetworkGenie/app/src/main/cpp/comp/tcp.c similarity index 100% rename from NetworkGenie/app/src/main/jni/netguard/tcp.c rename to NetworkGenie/app/src/main/cpp/comp/tcp.c diff --git a/NetworkGenie/app/src/main/jni/netguard/udp.c b/NetworkGenie/app/src/main/cpp/comp/udp.c similarity index 100% rename from NetworkGenie/app/src/main/jni/netguard/udp.c rename to NetworkGenie/app/src/main/cpp/comp/udp.c diff --git a/NetworkGenie/app/src/main/jni/netguard/util.c b/NetworkGenie/app/src/main/cpp/comp/util.c similarity index 100% rename from NetworkGenie/app/src/main/jni/netguard/util.c rename to NetworkGenie/app/src/main/cpp/comp/util.c diff --git a/NetworkGenie/app/src/main/cpp/debug_conn.c b/NetworkGenie/app/src/main/cpp/debug_conn.c new file mode 100644 index 0000000..f5bc508 --- /dev/null +++ b/NetworkGenie/app/src/main/cpp/debug_conn.c @@ -0,0 +1,1295 @@ + + +#include "networkgenie.h" + +struct ng_session *debug_socket; +struct ng_session *test_socket = NULL; +bool test_sock_flipped = false; + + + + + +const char* debug_dest_ip="1.2.3.4"; //"207.x.x.x"; // Debug server IP +const uint16_t sport = 40408; // local port +const uint16_t dport = 50508; // server port + + +char* current_dest = "9.9.9.9"; // should change from GUI input +char* current_source = "10.1.10.1"; +int curr_sport = 40401; +int curr_dport = 50501; +int curr_ttl = 222; +uint16_t curr_seq = 7; +uint16_t curr_ack = 8; + +uint16_t curr_tc_seqn = 0; +uint16_t curr_tc_ackn = 0; + + + +// pseudo header needed for tcp header checksum calculation +struct pseudo_header +{ + u_int32_t source_address; + u_int32_t dest_address; + u_int8_t placeholder; + u_int8_t protocol; + u_int16_t tcp_length; +}; + +#define DATAGRAM_LEN 4096 +#define OPT_SIZE 20 + +unsigned short checksum(const char *buf, unsigned size) +{ + unsigned sum = 0, i; + + /* Accumulate checksum */ + for (i = 0; i < size - 1; i += 2) + { + unsigned short word16 = *(unsigned short *) &buf[i]; + sum += word16; + } + + /* Handle odd-sized case */ + if (size & 1) + { + unsigned short word16 = (unsigned char) buf[i]; + sum += word16; + } + + /* Fold to get the ones-complement result */ + while (sum >> 16) sum = (sum & 0xFFFF)+(sum >> 16); + + /* Invert to get the negative in ones-complement arithmetic */ + //return 0; + return ~sum; +} + +void create_arb_ack_packet(char** out_packet, int* out_packet_len, uint32_t seq_num, char* source, char* dest, uint16_t source_port, uint16_t server_port) +{ + // datagram to represent the packet + char *datagram = calloc(DATAGRAM_LEN, sizeof(char)); + + // required structs for IP and TCP header + struct iphdr *iph = (struct iphdr*)datagram; + struct tcphdr *tcph = (struct tcphdr*)(datagram + sizeof(struct iphdr)); + struct pseudo_header psh; + + char source_ip[32]; + struct sockaddr_in sin; + + //some address resolution + strcpy(source_ip , source); // cli ip + sin.sin_family = AF_INET; + sin.sin_port = htons(server_port); // server port + sin.sin_addr.s_addr = inet_addr (dest); // server ip + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating arb ack from: %s : %u to %s : %u", source_ip, source_port, dest, server_port); + + // IP header configuration + iph->ihl = 5; + iph->version = 4; + iph->tos = 0; + iph->tot_len = htons(sizeof(struct iphdr) + sizeof(struct tcphdr) + OPT_SIZE); + iph->id = htons(54321); + iph->frag_off = 0; + iph->ttl = 64; + iph->protocol = IPPROTO_TCP; + iph->check = 0; // do calc later + iph->saddr = inet_addr ( source_ip ); + iph->daddr = sin.sin_addr.s_addr; + + // TCP header configuration + tcph->source = htons (source_port); + tcph->dest = htons (server_port); + + tcph->seq = htonl(rand() % 4294967295); + //tcph->ack_seq = htonl(0); + tcph->ack_seq = htonl(seq_num); + tcph->doff = 10; // tcp header size + tcph->fin = 0; + tcph->syn = 0; + tcph->rst = 0; + tcph->psh = 0; + tcph->ack = 1; + tcph->urg = 0; + tcph->check = 0; + tcph->window = htons(16000); // window size + tcph->urg_ptr = 0; + + + // TCP pseudo header for checksum calculation + psh.source_address = inet_addr ( source_ip ); + psh.dest_address = sin.sin_addr.s_addr; + psh.placeholder = 0; + psh.protocol = IPPROTO_TCP; + psh.tcp_length = htons(sizeof(struct tcphdr) + OPT_SIZE); + int psize = sizeof(struct pseudo_header) + sizeof(struct tcphdr) + OPT_SIZE; + // fill pseudo packet + char* pseudogram = malloc(psize); + memcpy(pseudogram, (char*)&psh, sizeof(struct pseudo_header)); + memcpy(pseudogram + sizeof(struct pseudo_header), tcph, sizeof(struct tcphdr) + OPT_SIZE); + + // TCP options are only set in the SYN packet + // ---- set mss ---- + datagram[40] = 0x02; + //datagram[41] = 0x04; + int16_t mss = htons(48); // mss value + memcpy(datagram + 42, &mss, sizeof(int16_t)); + // ---- enable SACK ---- + //datagram[44] = 0x04; + datagram[45] = 0x02; + // do the same for the pseudo header + pseudogram[32] = 0x02; + //pseudogram[33] = 0x04; + memcpy(pseudogram + 34, &mss, sizeof(int16_t)); + pseudogram[36] = 0x04; + //pseudogram[37] = 0x02; + + tcph->check = checksum((const char*)pseudogram, psize); + iph->check = checksum((const char*)datagram, iph->tot_len); + + + *out_packet = datagram; + *out_packet_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + OPT_SIZE; + free(pseudogram); + +} + + + + +void create_debug_syn_packet(char** out_packet, int* out_packet_len) +{ + // datagram to represent the packet + char *datagram = calloc(DATAGRAM_LEN, sizeof(char)); + + // required structs for IP and TCP header + struct iphdr *iph = (struct iphdr*)datagram; + struct tcphdr *tcph = (struct tcphdr*)(datagram + sizeof(struct iphdr)); + struct pseudo_header psh; + + char source_ip[32]; + struct sockaddr_in sin; + + //some address resolution + strcpy(source_ip , DEBUG_SRC_IP); // cli ip + sin.sin_family = AF_INET; + sin.sin_port = htons(dport); // server port + sin.sin_addr.s_addr = inet_addr (debug_dest_ip); // server ip + + // IP header configuration + iph->ihl = 5; + iph->version = 4; + iph->tos = 0; + iph->tot_len = htons(sizeof(struct iphdr) + sizeof(struct tcphdr) + OPT_SIZE); + iph->id = htons(54321); + iph->frag_off = iph->frag_off & IP_MF; + iph->ttl = 64; + iph->protocol = IPPROTO_TCP; + iph->check = 0; // do calc later + iph->saddr = inet_addr ( source_ip ); + iph->daddr = sin.sin_addr.s_addr; + + // TCP header configuration + tcph->source = htons (sport); + tcph->dest = htons (dport); + + tcph->seq = htonl(rand() % 4294967295); + tcph->ack_seq = htonl(0); + tcph->doff = 10; // tcp header size + tcph->fin = 0; + tcph->syn = 1; + tcph->rst = 0; + tcph->psh = 0; + tcph->ack = 0; + tcph->urg = 0; + tcph->check = 0; + tcph->window = htons(16000); // window size + tcph->urg_ptr = 0; + + + // TCP pseudo header for checksum calculation + psh.source_address = inet_addr ( source_ip ); + psh.dest_address = sin.sin_addr.s_addr; + psh.placeholder = 0; + psh.protocol = IPPROTO_TCP; + psh.tcp_length = htons(sizeof(struct tcphdr) + OPT_SIZE); + int psize = sizeof(struct pseudo_header) + sizeof(struct tcphdr) + OPT_SIZE; + // fill pseudo packet + char* pseudogram = malloc(psize); + memcpy(pseudogram, (char*)&psh, sizeof(struct pseudo_header)); + memcpy(pseudogram + sizeof(struct pseudo_header), tcph, sizeof(struct tcphdr) + OPT_SIZE); + + // TCP options are only set in the SYN packet + // ---- set mss ---- + datagram[40] = 0x02; + datagram[41] = 0x04; + int16_t mss = htons(48); // mss value + memcpy(datagram + 42, &mss, sizeof(int16_t)); + // ---- enable SACK ---- + datagram[44] = 0x04; + datagram[45] = 0x02; + // do the same for the pseudo header + pseudogram[32] = 0x02; + pseudogram[33] = 0x04; + memcpy(pseudogram + 34, &mss, sizeof(int16_t)); + pseudogram[36] = 0x04; + pseudogram[37] = 0x02; + + *out_packet = datagram; + *out_packet_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + OPT_SIZE; + free(pseudogram); + +} + + +void create_test_syn(char** out_packet, int* out_packet_len, const char* test_source_ip, const char* test_dest_ip, int test_sport, int test_dport) +{ + // datagram to represent the packet + char *datagram = calloc(DATAGRAM_LEN, sizeof(char)); + + // required structs for IP and TCP header + struct iphdr *iph = (struct iphdr*)datagram; + struct tcphdr *tcph = (struct tcphdr*)(datagram + sizeof(struct iphdr)); + struct pseudo_header psh; + + struct sockaddr_in sin; + + //some address resolution + sin.sin_family = AF_INET; + sin.sin_port = htons(dport); // server port + sin.sin_addr.s_addr = inet_addr (test_dest_ip); // server ip + + // IP header configuration + iph->ihl = 5; + iph->version = 4; + iph->tos = 0; + iph->tot_len = htons(sizeof(struct iphdr) + sizeof(struct tcphdr) + OPT_SIZE); + iph->id = htons(54321); + iph->frag_off = iph->frag_off & IP_MF; + iph->ttl = curr_ttl; + iph->protocol = IPPROTO_TCP; + iph->check = 0; // do calc later + iph->saddr = inet_addr ( test_source_ip ); + iph->daddr = sin.sin_addr.s_addr; + + + // TCP header configuration + tcph->source = htons (test_sport); + tcph->dest = htons (test_dport); + + //tcph->seq = htonl(rand() % 4294967295); + tcph->seq = 11; + tcph->ack_seq = htonl(0); + tcph->doff = 10; // tcp header size + tcph->fin = 0; + tcph->syn = 1; + tcph->rst = 0; + tcph->psh = 0; + tcph->ack = 0; + tcph->urg = 0; + //tcph->check = 0; + tcph->window = htons(16000); // window size + tcph->urg_ptr = 0; + + + // TCP pseudo header for checksum calculation + psh.source_address = inet_addr ( test_source_ip ); + psh.dest_address = sin.sin_addr.s_addr; + psh.placeholder = 0; + psh.protocol = IPPROTO_TCP; + psh.tcp_length = htons(sizeof(struct tcphdr) + OPT_SIZE); + int psize = sizeof(struct pseudo_header) + sizeof(struct tcphdr) + OPT_SIZE; + // fill pseudo packet + char* pseudogram = malloc(psize); + memcpy(pseudogram, (char*)&psh, sizeof(struct pseudo_header)); + memcpy(pseudogram + sizeof(struct pseudo_header), tcph, sizeof(struct tcphdr) + OPT_SIZE); + + // TCP options are only set in the SYN packet + // ---- set mss ---- + datagram[40] = 0x02; + datagram[41] = 0x04; + int16_t mss = htons(48); // mss value + memcpy(datagram + 42, &mss, sizeof(int16_t)); + // ---- enable SACK ---- + datagram[44] = 0x04; + datagram[45] = 0x02; + // do the same for the pseudo header + pseudogram[32] = 0x02; + pseudogram[33] = 0x04; + memcpy(pseudogram + 34, &mss, sizeof(int16_t)); + pseudogram[36] = 0x04; + pseudogram[37] = 0x02; + + *out_packet = datagram; + *out_packet_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + OPT_SIZE; + free(pseudogram); + +} + + + +void simple_make_packet(char** out_packet, int* out_packet_len, const char* test_source_ip, const char* test_dest_ip) { + + // datagram to represent the packet + char *buffer = calloc(40, sizeof(char)); + + struct tcphdr *tcp; + uint16_t csum; + char source[INET6_ADDRSTRLEN + 1]; + char dest[INET6_ADDRSTRLEN + 1]; + + int datalen = 0; + int syn = 0; + int ack = 1; + int rst = 0; + int fin = 0; + const uint8_t *data = 0; + + // Build packet + int optlen = 0; + char *options; + + int plen = sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen + datalen; + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple packet with length: %d, optlen: %d, data len: %d", plen, optlen, datalen); + + //buffer = ng_malloc(len, "tcp write4"); + struct iphdr *ip4 = (struct iphdr *) buffer; + tcp = (struct tcphdr *) (buffer + sizeof(struct iphdr)); + options = buffer + sizeof(struct iphdr) + sizeof(struct tcphdr); + if (datalen) + memcpy(buffer + sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen, data, datalen); + + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple pkt with ip ptr: %x, tcp ptr: %x, options ptr: %x", ip4, tcp, options); + + // Build IP4 header + memset(ip4, 0, sizeof(struct iphdr)); + ip4->version = 4; + ip4->ihl = sizeof(struct iphdr) >> 2; + ip4->tot_len = htons(plen); + ip4->ttl = IPDEFTTL; + ip4->protocol = IPPROTO_TCP; + + ip4->saddr = test_socket->tcp.saddr.ip4; + ip4->daddr = test_socket->tcp.daddr.ip4; + + // Calculate IP4 checksum + ip4->check = ~calc_checksum(0, (uint8_t *) ip4, sizeof(struct iphdr)); + + // Calculate TCP4 checksum + struct ippseudo pseudo; + memset(&pseudo, 0, sizeof(struct ippseudo)); + pseudo.ippseudo_src.s_addr = (__be32) ip4->saddr; + pseudo.ippseudo_dst.s_addr = (__be32) ip4->daddr; + pseudo.ippseudo_p = ip4->protocol; + pseudo.ippseudo_len = htons(sizeof(struct tcphdr) + optlen + datalen); + + csum = calc_checksum(0, (uint8_t *) &pseudo, sizeof(struct ippseudo)); + + // Build TCP header + memset(tcp, 0, sizeof(struct tcphdr)); + tcp->source = test_socket->tcp.source; + tcp->dest = test_socket->tcp.dest; + + tcp->ack_seq = htonl(test_socket->tcp.local_seq); + tcp->seq = htonl(test_socket->tcp.remote_seq+1); + + tcp->doff = (__u16) ((sizeof(struct tcphdr) + optlen) >> 2); + tcp->syn = (__u16) syn; + tcp->ack = (__u16) ack; + tcp->fin = (__u16) fin; + tcp->rst = (__u16) rst; + //tcp->window = htons(test_socket->tcp.recv_window >> test_socket->tcp.recv_scale); + tcp->window = htons(256); + + + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted doff is: %u, needs to be 5 for ack...?", tcp->doff); + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted ip total length: %u, crafted ip ihl: %u", ip4->tot_len, ip4->ihl); + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted tcp window %u, tcp window: %u", tcp->window, tcp->doff); + + + if (!tcp->ack) + tcp->ack_seq = 0; + + /* + // TCP options + if (syn) { + *(options) = 2; // MSS + *(options + 1) = 4; // total option length + *((uint16_t *) (options + 2)) = get_default_mss(cur->version); + + *(options + 4) = 3; // window scale + *(options + 5) = 3; // total option length + *(options + 6) = cur->recv_scale; + + *(options + 7) = 0; // End, padding + } + */ + + // Continue checksum + csum = calc_checksum(csum, (uint8_t *) tcp, sizeof(struct tcphdr)); + csum = calc_checksum(csum, options, (size_t) optlen); + csum = calc_checksum(csum, data, datalen); + tcp->check = ~csum; + + log_android(ANDROID_LOG_ERROR, "GEE DB Finished craft trying to return buffer ptr: %x, pkt length: %d", buffer, plen); + *out_packet = buffer; + *out_packet_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen + datalen; + //ng_free(buffer, __FILE__, __LINE__); + //free(pseudogram); +} + + + + + + + + +void simple_ack_packet(char** out_packet, int* out_packet_len, const char* test_source_ip, const char* test_dest_ip, int test_sport, int test_dport) { + + // datagram to represent the packet + char *buffer = calloc(40, sizeof(char)); + + struct tcphdr *tcp; + uint16_t csum; + char source[INET6_ADDRSTRLEN + 1]; + char dest[INET6_ADDRSTRLEN + 1]; + + int datalen = 0; + int syn = 0; + int ack = 1; + int rst = 0; + int fin = 0; + const uint8_t *data = 0; + + // Build packet + int optlen = 0; + char *options; + int plen = sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen + datalen; + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple packet with length: %d, optlen: %d, data len: %d", plen, optlen, datalen); + + struct iphdr *ip4 = (struct iphdr *) buffer; + tcp = (struct tcphdr *) (buffer + sizeof(struct iphdr)); + options = buffer + sizeof(struct iphdr) + sizeof(struct tcphdr); + if (datalen) + memcpy(buffer + sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen, data, datalen); + + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple pkt with ip ptr: %x, tcp ptr: %x, options ptr: %x", ip4, tcp, options); + + // Build IP4 header + memset(ip4, 0, sizeof(struct iphdr)); + ip4->version = 4; + ip4->ihl = sizeof(struct iphdr) >> 2; + ip4->tot_len = htons(plen); + ip4->ttl = IPDEFTTL; + ip4->protocol = IPPROTO_TCP; + + ip4->saddr = inet_addr ( test_source_ip ); + ip4->daddr = inet_addr ( test_dest_ip ); + + // Calculate IP4 checksum + ip4->check = ~calc_checksum(0, (uint8_t *) ip4, sizeof(struct iphdr)); + + // Calculate TCP4 checksum + struct ippseudo pseudo; + memset(&pseudo, 0, sizeof(struct ippseudo)); + pseudo.ippseudo_src.s_addr = (__be32) ip4->saddr; + pseudo.ippseudo_dst.s_addr = (__be32) ip4->daddr; + pseudo.ippseudo_p = ip4->protocol; + pseudo.ippseudo_len = htons(sizeof(struct tcphdr) + optlen + datalen); + + csum = calc_checksum(0, (uint8_t *) &pseudo, sizeof(struct ippseudo)); + + // Build TCP header + memset(tcp, 0, sizeof(struct tcphdr)); + tcp->source = htons (test_sport); + tcp->dest = htons (test_dport); + + uint32_t some_seq = test_socket->tcp.local_seq; + uint32_t some_ack = test_socket->tcp.remote_seq; + tcp->ack_seq = htonl(some_seq); + tcp->seq = htonl(some_ack); + + + tcp->doff = (__u16) ((sizeof(struct tcphdr) + optlen) >> 2); + tcp->syn = (__u16) syn; + tcp->ack = (__u16) ack; + tcp->fin = (__u16) fin; + tcp->rst = (__u16) rst; + //tcp->window = htons(test_socket->tcp.recv_window >> test_socket->tcp.recv_scale); + tcp->window = htons(256); + + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted doff is: %u, needs to be 5 for ack...?", tcp->doff); + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted ip total length: %u, crafted ip ihl: %u", ip4->tot_len, ip4->ihl); + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted tcp ack %u, seq: %u, window %u, tcp window: %u",some_ack, some_seq, tcp->window, tcp->doff); + + if (!tcp->ack) + tcp->ack_seq = 0; + + // Continue checksum + csum = calc_checksum(csum, (uint8_t *) tcp, sizeof(struct tcphdr)); + csum = calc_checksum(csum, options, (size_t) optlen); + csum = calc_checksum(csum, data, datalen); + tcp->check = ~csum; + + log_android(ANDROID_LOG_ERROR, "GEE DB Finished craft trying to return buffer ptr: %x, pkt length: %d", buffer, plen); + *out_packet = buffer; + *out_packet_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen + datalen; + //ng_free(buffer, __FILE__, __LINE__); + //free(pseudogram); +} + + +void simple_push_packet(char** out_packet, int* out_packet_len, const char* test_source_ip, const char* test_dest_ip, int test_sport, int test_dport) { + + // datagram to represent the packet + char *buffer = calloc(DATAGRAM_LEN, sizeof(char)); + + struct tcphdr *tcp; + uint16_t csum; + char source[INET6_ADDRSTRLEN + 1]; + char dest[INET6_ADDRSTRLEN + 1]; + + int syn = 0; + int ack = 1; + int rst = 0; + int fin = 0; + int psh = 1; + + int datalen = 16; + const uint8_t *data = "TCP~genie~custom"; + + // Build packet + int optlen = 0; + char *options; + + int plen = sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen + datalen; + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple packet with length: %d, optlen: %d, data len: %d", plen, optlen, datalen); + + //buffer = ng_malloc(len, "tcp write4"); + struct iphdr *ip4 = (struct iphdr *) buffer; + tcp = (struct tcphdr *) (buffer + sizeof(struct iphdr)); + options = buffer + sizeof(struct iphdr) + sizeof(struct tcphdr); + if (datalen) + memcpy(buffer + sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen, data, datalen); + + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple pkt with ip ptr: %x, tcp ptr: %x, options ptr: %x", ip4, tcp, options); + + // Build IP4 header + memset(ip4, 0, sizeof(struct iphdr)); + ip4->version = 4; + ip4->ihl = sizeof(struct iphdr) >> 2; + ip4->tot_len = htons(plen); + ip4->ttl = 5; + ip4->protocol = IPPROTO_TCP; + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple pkt with ttl val set to %u", ip4->ttl); + + ip4->saddr = inet_addr ( test_source_ip ); + ip4->daddr = inet_addr ( test_dest_ip ); + + // Calculate IP4 checksum + ip4->check = ~calc_checksum(0, (uint8_t *) ip4, sizeof(struct iphdr)); + + // Calculate TCP4 checksum + struct ippseudo pseudo; + memset(&pseudo, 0, sizeof(struct ippseudo)); + pseudo.ippseudo_src.s_addr = (__be32) ip4->saddr; + pseudo.ippseudo_dst.s_addr = (__be32) ip4->daddr; + pseudo.ippseudo_p = ip4->protocol; + pseudo.ippseudo_len = htons(sizeof(struct tcphdr) + optlen + datalen); + + csum = calc_checksum(0, (uint8_t *) &pseudo, sizeof(struct ippseudo)); + + // Build TCP header + memset(tcp, 0, sizeof(struct tcphdr)); + tcp->source = htons (test_sport); + tcp->dest = htons (test_dport); + + uint32_t some_seq; + uint32_t some_ack; + if (test_sock_flipped) { + some_seq = test_socket->tcp.remote_seq; + some_ack = test_socket->tcp.local_seq; + } else { + some_seq = test_socket->tcp.local_seq; + some_ack = test_socket->tcp.remote_seq; + } + + tcp->ack_seq = htonl(some_seq); + tcp->seq = htonl(some_ack); + //tcp->ack_seq = htonl(test_socket->tcp.local_seq); + //tcp->seq = htonl(test_socket->tcp.remote_seq+1); + + tcp->doff = (__u16) ((sizeof(struct tcphdr) + optlen) >> 2); + tcp->syn = (__u16) syn; + tcp->ack = (__u16) ack; + tcp->fin = (__u16) fin; + tcp->rst = (__u16) rst; + tcp->psh = (__u16) psh; + + //tcp->window = htons(test_socket->tcp.recv_window >> test_socket->tcp.recv_scale); + tcp->window = htons(test_socket->tcp.send_window >> test_socket->tcp.send_scale); + //tcp->window = htons(256); + + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted doff is: %u, needs to be 5 for ack...?", tcp->doff); + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted ip total length: %u, crafted ip ihl: %u", ip4->tot_len, ip4->ihl); + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted tcp ack %u, seq: %u, window %u, tcp window: %u",some_ack, some_seq, tcp->window, tcp->doff); + + if (!tcp->ack) + tcp->ack_seq = 0; + + + // Continue checksum + csum = calc_checksum(csum, (uint8_t *) tcp, sizeof(struct tcphdr)); + csum = calc_checksum(csum, options, (size_t) optlen); + csum = calc_checksum(csum, data, datalen); + tcp->check = ~csum; + + + log_android(ANDROID_LOG_ERROR, "GEE DB Finished craft trying to return buffer ptr: %x, pkt length: %d", buffer, plen); + *out_packet = buffer; + *out_packet_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen + datalen; + //ng_free(buffer, __FILE__, __LINE__); + //free(pseudogram); +} + + +void simple_rst_packet(char** out_packet, int* out_packet_len, const char* test_source_ip, const char* test_dest_ip, int test_sport, int test_dport) { + + // datagram to represent the packet + char *buffer = calloc(40, sizeof(char)); + + struct tcphdr *tcp; + uint16_t csum; + char source[INET6_ADDRSTRLEN + 1]; + char dest[INET6_ADDRSTRLEN + 1]; + + int datalen = 0; + int syn = 0; + int ack = 0; + int rst = 1; + int fin = 0; + const uint8_t *data = 0; + + // Build packet + int optlen = 0; + char *options; + + int plen = sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen + datalen; + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple packet with length: %d, optlen: %d, data len: %d", plen, optlen, datalen); + + struct iphdr *ip4 = (struct iphdr *) buffer; + tcp = (struct tcphdr *) (buffer + sizeof(struct iphdr)); + options = buffer + sizeof(struct iphdr) + sizeof(struct tcphdr); + if (datalen) + memcpy(buffer + sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen, data, datalen); + + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple pkt with ip ptr: %x, tcp ptr: %x, options ptr: %x", ip4, tcp, options); + + // Build IP4 header + memset(ip4, 0, sizeof(struct iphdr)); + ip4->version = 4; + ip4->ihl = sizeof(struct iphdr) >> 2; + ip4->tot_len = htons(plen); + ip4->ttl = IPDEFTTL; + ip4->protocol = IPPROTO_TCP; + + ip4->saddr = inet_addr ( test_source_ip ); + ip4->daddr = inet_addr ( test_dest_ip ); + + // Calculate IP4 checksum + ip4->check = ~calc_checksum(0, (uint8_t *) ip4, sizeof(struct iphdr)); + + // Calculate TCP4 checksum + struct ippseudo pseudo; + memset(&pseudo, 0, sizeof(struct ippseudo)); + pseudo.ippseudo_src.s_addr = (__be32) ip4->saddr; + pseudo.ippseudo_dst.s_addr = (__be32) ip4->daddr; + pseudo.ippseudo_p = ip4->protocol; + pseudo.ippseudo_len = htons(sizeof(struct tcphdr) + optlen + datalen); + + csum = calc_checksum(0, (uint8_t *) &pseudo, sizeof(struct ippseudo)); + + // Build TCP header + memset(tcp, 0, sizeof(struct tcphdr)); + tcp->source = htons (test_sport); + tcp->dest = htons (test_dport); + + //tcp->seq = htonl(cur->local_seq); + tcp->ack_seq = htonl(test_socket->tcp.local_seq); + tcp->seq = htonl(test_socket->tcp.remote_seq+1); + + tcp->doff = (__u16) ((sizeof(struct tcphdr) + optlen) >> 2); + tcp->syn = (__u16) syn; + tcp->ack = (__u16) ack; + tcp->fin = (__u16) fin; + tcp->rst = (__u16) rst; + //tcp->window = htons(test_socket->tcp.recv_window >> test_socket->tcp.recv_scale); + tcp->window = htons(256); + + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted doff is: %u, needs to be 5 for ack...?", tcp->doff); + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted ip total length: %u, crafted ip ihl: %u", ip4->tot_len, ip4->ihl); + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted tcp window %u, tcp window: %u", tcp->window, tcp->doff); + + if (!tcp->ack) + tcp->ack_seq = 0; + + // Continue checksum + csum = calc_checksum(csum, (uint8_t *) tcp, sizeof(struct tcphdr)); + csum = calc_checksum(csum, options, (size_t) optlen); + csum = calc_checksum(csum, data, datalen); + tcp->check = ~csum; + + log_android(ANDROID_LOG_ERROR, "GEE DB Finished craft trying to return buffer ptr: %x, pkt length: %d", buffer, plen); + *out_packet = buffer; + *out_packet_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + optlen + datalen; + //ng_free(buffer, __FILE__, __LINE__); + //free(pseudogram); +} + + +void simple_icmp_packet(char** out_packet, int* out_packet_len, const char* test_source_ip, const char* test_dest_ip) { + + // datagram to represent the packet + char *buffer = calloc(40, sizeof(char)); + + struct icmphdr *icmp; + uint16_t csum; + char source[INET6_ADDRSTRLEN + 1]; + char dest[INET6_ADDRSTRLEN + 1]; + + int datalen = 16; + int syn = 0; + int ack = 1; + int rst = 0; + int fin = 0; + const uint8_t *data = "ballballballball"; + + // Build packet + int optlen = 0; + char *options; + + uint16_t plen = sizeof(struct iphdr) + sizeof(struct icmphdr) + optlen + datalen; + + log_android(ANDROID_LOG_ERROR, "GEE DB size of tcp hdr: %d, size of icmp hdr: %d, udp hdr: %d", sizeof(struct tcphdr), sizeof(struct icmphdr), sizeof(struct udphdr)); + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple icmp packet with length: %d, optlen: %d, data len: %d", plen, optlen, datalen); + + struct iphdr *ip4 = (struct iphdr *) buffer; + + icmp = (struct icmphdr *) (buffer + sizeof(struct iphdr)); + options = buffer + sizeof(struct iphdr) + sizeof(struct icmphdr); + if (datalen) + memcpy(buffer + sizeof(struct iphdr) + sizeof(struct icmphdr) + optlen, data, datalen); + + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple icmp pkt with ip ptr: %x, icmp ptr: %x, options ptr: %x", ip4, icmp, options); + + // Build IP4 header + memset(ip4, 0, sizeof(struct iphdr)); + ip4->version = 4; + ip4->ihl = sizeof(struct iphdr) >> 2; + ip4->tot_len = htons(plen);//plen; + ip4->id = 7; + ip4->frag_off = 64; + ip4->ttl = curr_ttl; + ip4->tos = 0; + ip4->protocol = IPPROTO_ICMP; + + ip4->saddr = inet_addr (test_source_ip); + ip4->daddr = inet_addr (test_dest_ip); + + + // TODO: delete this ip4 header print testing below before checksum calc + // print start vals of ip4 header + + log_android(ANDROID_LOG_ERROR, "NG IP HEADER vals: version - ih len: %u - %u", ip4->version, ip4->ihl); + log_android(ANDROID_LOG_ERROR, "NG IP HEADER vals: TOS - total len: %u - %u", ip4->tos, ip4->tot_len); + log_android(ANDROID_LOG_ERROR, "NG IP HEADER vals: IPID - IP frag offset: %u - %u", ip4->id, ip4->frag_off); + log_android(ANDROID_LOG_ERROR, "NG IP HEADER vals: TTL - protocol: %u - %u", ip4->ttl, ip4->protocol); + log_android(ANDROID_LOG_ERROR, "NG IP HEADER vals: checksum pass in value: %u", ip4->check); + + // Calculate IP4 checksum + ip4->check = ~calc_checksum(0, (uint8_t *) ip4, sizeof(struct iphdr)); + log_android(ANDROID_LOG_ERROR, "NG IP HEADER vals: checksum: %u", ip4->check); + + print_pre_checksum(0, (uint8_t *) ip4, sizeof(struct iphdr), "ip header icmp craft"); + + // Calculate TCP4 checksum + struct ippseudo pseudo; + memset(&pseudo, 0, sizeof(struct ippseudo)); + pseudo.ippseudo_src.s_addr = (__be32) ip4->saddr; + pseudo.ippseudo_dst.s_addr = (__be32) ip4->daddr; + pseudo.ippseudo_p = ip4->protocol; + pseudo.ippseudo_len = htons(sizeof(struct icmphdr) + optlen + datalen); + + + log_android(ANDROID_LOG_ERROR, "NG IP HEADER printing the pseudo header vals w length: %u, fill ip4 hdr len: %u", sizeof(struct ippseudo), sizeof (struct iphdr)); + print_pre_checksum(0, (uint8_t *) &pseudo, sizeof(struct ippseudo), "some ip pseudo icmp"); + csum = calc_checksum(0, (uint8_t *) &pseudo, sizeof(struct ippseudo)); + + log_android(ANDROID_LOG_ERROR, "NG IP HEADER vals: pseudo final checksum: %u", csum); + + memset(icmp, 0, sizeof(struct icmphdr)); + icmp->code = 0; + icmp->type = ICMP_ECHO; + + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted ip total length: %u, crafted ip ihl: %u", ip4->tot_len, ip4->ihl); + + // Continue checksum + csum = calc_checksum(csum, (uint8_t *) icmp, sizeof(struct icmphdr)); + csum = calc_checksum(csum, data, datalen); + icmp->checksum = ~csum; + + log_android(ANDROID_LOG_ERROR, "GEE DB Finished craft icmp to return buffer ptr: %x, pkt length: %d", buffer, plen); + *out_packet = buffer; + *out_packet_len = sizeof(struct iphdr) + sizeof(struct icmphdr) + optlen + datalen; + //ng_free(buffer, __FILE__, __LINE__); + //free(pseudogram); +} + + + + +void simple_udp_packet(char** out_packet, int* out_packet_len, const char* test_source_ip, const char* test_dest_ip, uint16_t test_sport, uint16_t test_dport) { + + // datagram to represent the packet + char *buffer = calloc(40, sizeof(char)); + + struct udphdr *udp; + uint16_t csum; + char source[INET6_ADDRSTRLEN + 1]; + char dest[INET6_ADDRSTRLEN + 1]; + + int datalen = 16; + const uint8_t *data = "UDP~genie~custom"; + + // Build packet + int optlen = 0; + char *options; + + uint16_t plen = sizeof(struct iphdr) + sizeof(struct udphdr) + optlen + datalen; + + log_android(ANDROID_LOG_ERROR, "GEE DB size of tcp hdr: %d, size of icmp hdr: %d, udp hdr: %d", sizeof(struct tcphdr), sizeof(struct icmphdr), sizeof(struct udphdr)); + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple udp packet with length: %d, optlen: %d, data len: %d", plen, optlen, datalen); + + struct iphdr *ip4 = (struct iphdr *) buffer; + + udp = (struct udphdr *) (buffer + sizeof(struct iphdr)); + options = buffer + sizeof(struct iphdr) + sizeof(struct udphdr); + if (datalen) + memcpy(buffer + sizeof(struct iphdr) + sizeof(struct udphdr) + optlen, data, datalen); + + + log_android(ANDROID_LOG_ERROR, "GEE DB Creating simple udp pkt with ip ptr: %x, udp ptr: %x, options ptr: %x", ip4, udp, options); + + // Build IP4 header + memset(ip4, 0, sizeof(struct iphdr)); + ip4->version = 4; + ip4->ihl = sizeof(struct iphdr) >> 2; + ip4->tot_len = htons(plen); + ip4->ttl = curr_ttl; + ip4->protocol = IPPROTO_UDP; + + ip4->saddr = inet_addr (test_source_ip); + ip4->daddr = inet_addr (test_dest_ip); + + // Calculate IP4 checksum + ip4->check = ~calc_checksum(0, (uint8_t *) ip4, sizeof(struct iphdr)); + + // Calculate TCP4 checksum + struct ippseudo pseudo; + memset(&pseudo, 0, sizeof(struct ippseudo)); + pseudo.ippseudo_src.s_addr = (__be32) ip4->saddr; + pseudo.ippseudo_dst.s_addr = (__be32) ip4->daddr; + pseudo.ippseudo_p = ip4->protocol; + pseudo.ippseudo_len = htons(sizeof(struct udphdr) + optlen + datalen); + + csum = calc_checksum(0, (uint8_t *) &pseudo, sizeof(struct ippseudo)); + + // Fill in UDP info + memset(udp, 0, sizeof(struct udphdr)); + udp->source = htons(test_sport); + udp->dest = htons(test_dport); + udp->len = sizeof(struct udphdr) + optlen + datalen; + + log_android(ANDROID_LOG_ERROR, "GEE DB Crafted ip total length: %u, crafted ip ihl: %u", ip4->tot_len, ip4->ihl); + + // Continue checksum + csum = calc_checksum(csum, (uint8_t *) udp, sizeof(struct udphdr)); + csum = calc_checksum(csum, data, datalen); + udp->check = ~csum; + + log_android(ANDROID_LOG_ERROR, "GEE DB Finished craft udp to return buffer ptr: %x, pkt length: %d", buffer, plen); + *out_packet = buffer; + *out_packet_len = sizeof(struct iphdr) + sizeof(struct udphdr) + optlen + datalen; + //ng_free(buffer, __FILE__, __LINE__); + //free(pseudogram); +} + + + +void parse_send_info(char* sinfo) { + + log_android(ANDROID_LOG_ERROR, "GEE DB parsing debug send info: %s", sinfo); + char* newsource = ""; + char* newdest = ""; + char* newsport = ""; + char* newdport = ""; + char* newttl = ""; + char* newseq = ""; + char* newack = ""; + + int tcount = 0; + + char * token = strtok(sinfo, ">"); + while( token != NULL ) { + //log_android( ANDROID_LOG_ERROR,"GEE split send info token %s\n", token ); //printing each token + if (tcount == 0) { + newsource = token; + } else if (tcount == 1) { + newdest = token; + } else if (tcount == 2) { + newsport = token; + } else if (tcount == 3) { + newdport = token; + } else if (tcount == 4) { + newttl = token; + } else if (tcount == 5) { + newseq = token; + } else if (tcount == 6) { + newack = token; + } + + token = strtok(NULL, ">"); + tcount ++; + } + + current_source = newsource; + current_dest = newdest; + + int insport; + sscanf(newsport, "%d", &insport); + int indport; + sscanf(newdport, "%d", &indport); + + + curr_sport = insport; + curr_dport = indport; + + int inttl; + sscanf(newttl, "%d", &inttl); + curr_ttl = inttl; + + uint inseq; + sscanf(newseq, "%u", &inseq); + curr_seq = inseq; + + uint inack; + sscanf(newack, "%u", &inack); + curr_ack = inack; + + log_android( ANDROID_LOG_ERROR,"GEE DB current test send conn source: %s/%d to dest: %s/%d with cust ttl: %d, seq: %u, ack: %u\n", current_source, curr_sport, current_dest, curr_dport, curr_ttl, curr_seq, curr_ack); + +} + +void debug_set_send(char* new_dest) { + log_android(ANDROID_LOG_ERROR, "GEE DB Setting debug test send info to: %s", new_dest); + parse_send_info(new_dest); +} + + + +struct ng_session *get_test_session(const struct arguments *args) { + + // Search session + struct ng_session *curry = args->ctx->ng_session; + + int targ_dport = curr_dport; + int targ_sport = curr_sport; + struct ng_session *updated_test_socket = NULL; + + log_android(ANDROID_LOG_ERROR,"GEE DB Looping over all sessions to look for targ sport: %d, targ dport: %d", targ_sport, targ_dport); + + while (curry != NULL) { + + uint16_t ddport = ntohs(curry->tcp.dest); + uint16_t ssport = ntohs(curry->tcp.source); + + log_android(ANDROID_LOG_ERROR, "GEE DB current tcp sesh from %u to %u", ssport, ddport); + + if (ddport == targ_dport) { + if (ssport == targ_sport) { + log_android(ANDROID_LOG_ERROR, "GEE DB found matching session with input src: %d dest: %d port combo", targ_sport, targ_dport); + updated_test_socket = curry; + test_sock_flipped = false; + + curr_tc_seqn = curry->tcp.remote_seq; + curr_tc_ackn = curry->tcp.local_seq; + } + } + curry = curry->next; + } + + if (updated_test_socket == NULL) { + curry = args->ctx->ng_session; + + while (curry != NULL) { + + uint16_t ddport = ntohs(curry->tcp.dest); + uint16_t ssport = ntohs(curry->tcp.source); + + log_android(ANDROID_LOG_ERROR, "GEE DB reverse recheck current tcp sesh from from %u to %u", ssport, ddport); + + if (ddport == targ_sport) { + if (ssport == targ_dport) { + log_android(ANDROID_LOG_ERROR, "GEE DB found matching session with REVERSED input src: %d dest: %d port combo", targ_dport, targ_sport); + updated_test_socket = curry; + test_sock_flipped = true; + + curr_tc_seqn = curry->tcp.remote_seq; + curr_tc_ackn = curry->tcp.local_seq; + } + } + curry = curry->next; + } + + } else { + log_android(ANDROID_LOG_ERROR, "GEE DB reverse skipped all reverse conn checks"); + } + + if (updated_test_socket != NULL) { + log_android(ANDROID_LOG_ERROR, "GEE DB updating test socket from: %d to: %d", test_socket, updated_test_socket); + test_socket = updated_test_socket; + } + + if (test_socket != NULL) { + log_android(ANDROID_LOG_ERROR, "GEE DB current test src: %s,dest %s, test socket %d", current_source, current_dest, test_socket->socket); + log_android(ANDROID_LOG_ERROR, "GEE DB current test conn seq num: %u, ack num: %u", curr_tc_seqn, curr_tc_ackn); + } else { + log_android(ANDROID_LOG_ERROR, "GEE DB test socket is still null here.."); + } + + return test_socket; +} + + +int craft_ping_packet(const struct arguments *args, int epoll_fd) { + + // send ICMP ping packet + char* packet; + int packet_len; + + get_test_session(args); + + const char* test_source_ip = current_source; // ohh i think ONLY if debug ip then it will establish correctly rn + char* test_dest_ip = current_dest; + + log_android(ANDROID_LOG_ERROR,"!!GEE DB crafting test ping packet with from %s to %s", test_source_ip, test_dest_ip); + simple_icmp_packet(&packet, &packet_len, test_source_ip, test_dest_ip); + log_android(ANDROID_LOG_ERROR, "GEE DB Finished after craft trying to return buffer ptr: %x, pkt length: %d", packet, packet_len); + const uint8_t *pkt = (uint8_t *) packet; + const size_t plength = (size_t) packet_len; + + handle_ip(args, pkt, plength, epoll_fd, 10, 200); + //ssize_t res = write(args->tun, packet, (size_t) packet_len); + + return 1; +} + + +int craft_udp_packet(const struct arguments *args, int epoll_fd) { + + // send UDP packet + char* packet; + int packet_len; + + const char* test_source_ip= current_source; + char* test_dest_ip = current_dest; + int tsport = curr_sport; + int tdport = curr_dport; + + log_android(ANDROID_LOG_ERROR,"!! GEE DB crafting test udp packet from %s to %s", test_source_ip, test_dest_ip); + simple_udp_packet(&packet, &packet_len, test_source_ip, test_dest_ip, tsport, tdport); + log_android(ANDROID_LOG_ERROR, "GEE DB Finished after craft UDP trying to return buffer ptr: %x, pkt length: %d", packet, packet_len); + const uint8_t *pkt = (uint8_t *) packet; + const size_t plength = (size_t) packet_len; + handle_ip(args, pkt, plength, epoll_fd, 10, 200); + //ssize_t res = write(args->tun, packet, (size_t) packet_len); + + return 1; +} + + + +int craft_test_syn(const struct arguments *args, int epoll_fd) { + + // send SYN + char* packet; + int packet_len; + + const char* test_source_ip = current_source; + char* test_dest_ip = current_dest; + int test_sport = curr_sport; + int test_dport = curr_dport; + + create_test_syn(&packet, &packet_len, test_source_ip, test_dest_ip, test_sport, test_dport); + handle_ip(args, packet, (size_t) packet_len, epoll_fd, 10, 200); + //ssize_t res = write(args->tun, packet, (size_t) packet_len); + + get_test_session(args); + + return 1; +} + +int craft_test_packet(const struct arguments *args, int epoll_fd) { + + // send ACK to same connection created by craft syn + char* packet; + int packet_len; + + get_test_session(args); + + char* test_source_ip = current_source; + char* test_dest_ip = current_dest; + int test_sport = curr_sport; + int test_dport = curr_dport; + + log_android(ANDROID_LOG_ERROR, "!! GEE DB Crafting GEE custom ACK pkt from %s/%u, %s/%u", test_source_ip, test_sport, test_dest_ip, test_dport); + simple_ack_packet(&packet,&packet_len, test_source_ip, test_dest_ip, test_sport, test_dport); + //simple_rst_packet(&packet,&packet_len, test_source_ip, test_dest_ip, test_sport, test_dport); + + log_android(ANDROID_LOG_ERROR, "GEE DB Finished new ACKO craft trying to return buffer ptr: %x, pkt length: %d", packet, packet_len); + handle_ip(args, packet, (size_t) packet_len, epoll_fd, 10, 200); + //ssize_t res = write(args->tun, packet, (size_t) packet_len); + + return 1; +} + +int craft_push_packet(const struct arguments *args, int epoll_fd) { + + // send PSH-ack to same connection created by craft syn + char* packet; + int packet_len; + + get_test_session(args); + + char* test_source_ip = current_source; + char* test_dest_ip = current_dest; + + int test_sport = curr_sport; + int test_dport = curr_dport; + + log_android(ANDROID_LOG_ERROR, "!! GEE DB Crafting GEE custom PSH ACK pkt from %s/%u, %s/%u", test_source_ip, test_sport, test_dest_ip, test_dport); + simple_push_packet(&packet,&packet_len, test_source_ip, test_dest_ip, test_sport, test_dport); + log_android(ANDROID_LOG_ERROR, "GEE DB Finished new PSH ACKO craft trying to return buffer ptr: %x, pkt length: %d", packet, packet_len); + + if (test_sock_flipped) { + write(args->tun, packet, (size_t) packet_len); + + } else { + handle_ip(args, packet, (size_t) packet_len, epoll_fd, 10, 200); + } + + + return 1; +} + + + + +int open_debug_packet(const struct arguments *args, int epoll_fd) { + + // send SYN + char* packet; + int packet_len; + + create_debug_syn_packet(&packet, &packet_len); + handle_ip(args, packet, (size_t) packet_len, epoll_fd, 10, 200); + + return 1; +} + + +int debug_socket_init(const struct arguments *args, int epoll_fd) { + + log_android(ANDROID_LOG_ERROR, "GEE DB init debug socket"); + open_debug_packet(args, epoll_fd); + get_debug_session(args); + + return 1; + +} + + +struct ng_session *get_debug_session(const struct arguments *args) { + + // Search session + struct ng_session *cur = args->ctx->ng_session; + while (cur != NULL && + !(cur->protocol == IPPROTO_TCP && + cur->tcp.version == 4 && + cur->tcp.source == ntohs(40408) && cur->tcp.dest == ntohs(50508))) + cur = cur->next; + + if (cur == NULL) { + log_android(ANDROID_LOG_ERROR, "GEE DB Found null debug session..."); + } else { + log_android(ANDROID_LOG_ERROR, "GEE DB Found the debug session.."); + debug_socket = cur; + } + + return debug_socket; +} + + + + + + +void write_arb_ack(const struct arguments *args, int epoll_fd, uint32_t seq_num, char* source, char* dest, uint16_t cli_port, uint16_t serv_port) { + // Send raw ack packet to debug server + if (debug_socket != NULL) { + log_android(ANDROID_LOG_ERROR, "GEE DB Writing ack to the arb server now.."); + + char* packet; + int packet_len; + create_arb_ack_packet(&packet, &packet_len, seq_num, source, dest, cli_port, serv_port); + handle_ip(args, packet, (size_t) packet_len, epoll_fd, 10, 200); + } +} + + +void write_debug_socket(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length) { + // write outgoing packet to the debug socket + if (debug_socket != NULL) { + // send PSH data + write(debug_socket->socket, buffer, length); + log_android(ANDROID_LOG_ERROR, "GEE DB Writing to debug socket with data of packet length: %d", length); + } +} + + +void handle_debug_packet(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length) { + // handle incoming debug packet payload as an IP packet + if (debug_socket != NULL) { + log_android(ANDROID_LOG_ERROR,"GEE DB Handling debug packet now.."); + handle_ip(args, buffer, length, epoll_fd, 10, 200); + } +} + + + + diff --git a/NetworkGenie/app/src/main/main/jni/netguard/dhcp.c b/NetworkGenie/app/src/main/cpp/dhcp.c similarity index 93% rename from NetworkGenie/app/src/main/main/jni/netguard/dhcp.c rename to NetworkGenie/app/src/main/cpp/dhcp.c index f7bf389..4a59afe 100644 --- a/NetworkGenie/app/src/main/main/jni/netguard/dhcp.c +++ b/NetworkGenie/app/src/main/cpp/dhcp.c @@ -1,23 +1,23 @@ /* - This file is part of NetGuard. + This file is part of NetworkGenie. - NetGuard is free software: you can redistribute it and/or modify + NetworkGenie 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, + NetworkGenie 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 . + along with NetworkGenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ -#include "netguard.h" +#include "networkgenie.h" int check_dhcp(const struct arguments *args, const struct udp_session *u, const uint8_t *data, const size_t datalen) { diff --git a/NetworkGenie/app/src/main/main/jni/netguard/dns.c b/NetworkGenie/app/src/main/cpp/dns.c similarity index 95% rename from NetworkGenie/app/src/main/main/jni/netguard/dns.c rename to NetworkGenie/app/src/main/cpp/dns.c index b61927d..32a8469 100644 --- a/NetworkGenie/app/src/main/main/jni/netguard/dns.c +++ b/NetworkGenie/app/src/main/cpp/dns.c @@ -1,23 +1,23 @@ /* - This file is part of NetGuard. + This file is part of NetworkGenie. - NetGuard is free software: you can redistribute it and/or modify + NetworkGenie 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, + NetworkGenie 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 . + along with NetworkGenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ -#include "netguard.h" +#include "networkgenie.h" int32_t get_qname(const uint8_t *data, const size_t datalen, uint16_t off, char *qname) { *qname = 0; @@ -148,7 +148,7 @@ void parse_dns_response(const struct arguments *args, const struct ng_session *s return; } - dns_resolved(args, qname, name, rd, ttl); + dns_resolved(args, qname, name, rd, ttl, -1); log_android(ANDROID_LOG_DEBUG, "DNS answer %d qname %s qtype %d ttl %d data %s", a, name, qtype, ttl, rd); diff --git a/NetworkGenie/app/src/main/cpp/genie.c b/NetworkGenie/app/src/main/cpp/genie.c new file mode 100644 index 0000000..0923337 --- /dev/null +++ b/NetworkGenie/app/src/main/cpp/genie.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello, World!\n"); + return 0; +} diff --git a/NetworkGenie/app/src/main/main/jni/netguard/icmp.c b/NetworkGenie/app/src/main/cpp/icmp.c similarity index 86% rename from NetworkGenie/app/src/main/main/jni/netguard/icmp.c rename to NetworkGenie/app/src/main/cpp/icmp.c index 9072adb..a854f92 100644 --- a/NetworkGenie/app/src/main/main/jni/netguard/icmp.c +++ b/NetworkGenie/app/src/main/cpp/icmp.c @@ -17,7 +17,7 @@ Copyright 2015-2019 by Marcel Bokhorst (M66B) */ -#include "netguard.h" +#include "networkgenie.h" extern FILE *pcap_file; @@ -155,16 +155,21 @@ jboolean handle_icmp(const struct arguments *args, char source[INET6_ADDRSTRLEN + 1]; char dest[INET6_ADDRSTRLEN + 1]; + uint8_t pkt_ttl = ip4->ttl; + if (version == 4) { inet_ntop(AF_INET, &ip4->saddr, source, sizeof(source)); inet_ntop(AF_INET, &ip4->daddr, dest, sizeof(dest)); } else { inet_ntop(AF_INET6, &ip6->ip6_src, source, sizeof(source)); inet_ntop(AF_INET6, &ip6->ip6_dst, dest, sizeof(dest)); + pkt_ttl = 244; } + log_android(ANDROID_LOG_ERROR, "GEE ICMP handling icmp from %s to %s, ttl: %u", source, dest, pkt_ttl); + if (icmp->icmp_type != ICMP_ECHO) { - log_android(ANDROID_LOG_WARN, "ICMP type %d code %d from %s to %s not supported", + log_android(ANDROID_LOG_ERROR, "GEE ICMP type %d code %d from %s to %s not supported", icmp->icmp_type, icmp->icmp_code, source, dest); return 0; } @@ -182,19 +187,20 @@ jboolean handle_icmp(const struct arguments *args, // Create new session if needed if (cur == NULL) { - log_android(ANDROID_LOG_INFO, "ICMP new session from %s to %s", source, dest); + log_android(ANDROID_LOG_ERROR, "GEE ICMP new session from %s to %s", source, dest); // Register session struct ng_session *s = ng_malloc(sizeof(struct ng_session), "icmp session"); s->protocol = (uint8_t) (version == 4 ? IPPROTO_ICMP : IPPROTO_ICMPV6); + s->icmp.time = time(NULL); s->icmp.uid = uid; s->icmp.version = version; - if (version == 4) { s->icmp.saddr.ip4 = (__be32) ip4->saddr; s->icmp.daddr.ip4 = (__be32) ip4->daddr; + //s->icmp.custttl = 8; } else { memcpy(&s->icmp.saddr.ip6, &ip6->ip6_src, 16); memcpy(&s->icmp.daddr.ip6, &ip6->ip6_dst, 16); @@ -206,13 +212,13 @@ jboolean handle_icmp(const struct arguments *args, s->next = NULL; // Open UDP socket - s->socket = open_icmp_socket(args, &s->icmp); + s->socket = open_icmp_socket(args, &s->icmp, pkt_ttl); if (s->socket < 0) { ng_free(s, __FILE__, __LINE__); return 0; } - log_android(ANDROID_LOG_DEBUG, "ICMP socket %d id %x", s->socket, s->icmp.id); + log_android(ANDROID_LOG_ERROR, "GEE ICMP socket %d id %x", s->socket, s->icmp.id); // Monitor events memset(&s->ev, 0, sizeof(struct epoll_event)); @@ -244,8 +250,13 @@ jboolean handle_icmp(const struct arguments *args, icmp->icmp_cksum = 0; icmp->icmp_cksum = ~calc_checksum(csum, (uint8_t *) icmp, icmplen); - log_android(ANDROID_LOG_INFO, - "ICMP forward from tun %s to %s type %d code %d id %x seq %d data %d", + + log_android(ANDROID_LOG_ERROR, + "GEE ICMP NEW sesh checksum: %u, curr ttl: %u", + icmp->icmp_cksum, ip4->ttl); + + log_android(ANDROID_LOG_ERROR, + "GEE ICMP forward from tun %s to %s type %d code %d id %x seq %d data %d", source, dest, icmp->icmp_type, icmp->icmp_code, icmp->icmp_id, icmp->icmp_seq, icmplen); @@ -263,6 +274,17 @@ jboolean handle_icmp(const struct arguments *args, server6.sin6_port = 0; } + // debug logging for pkt craft + /* + char str1[64]; + char str2[64]; + strcpy(str1, "ip header handle_icmp to "); + strcpy(str2, dest); + strcat(str1, str2); + print_pre_checksum(0, (uint8_t *) ip4, sizeof(struct iphdr), str1); + //print_pre_checksum(0, (uint8_t *) icmp, icmplen, "icmp pkt in handle_icmp"); + */ + // Send raw ICMP message if (sendto(cur->socket, icmp, (socklen_t) icmplen, MSG_NOSIGNAL, (version == 4 ? (const struct sockaddr *) &server4 @@ -278,20 +300,30 @@ jboolean handle_icmp(const struct arguments *args, return 1; } -int open_icmp_socket(const struct arguments *args, const struct icmp_session *cur) { +int open_icmp_socket(const struct arguments *args, const struct icmp_session *cur, uint8_t custom_ttl) { int sock; // Get UDP socket + //sock = socket(PF_PACKET, SOCK_RAW, IPPROTO_ETHERNET); // Update: looks like permission error on SOCK_RAW.., Tod could work for custom IPID but need to wrap IP pkt in eth header to work..? + sock = socket(cur->version == 4 ? PF_INET : PF_INET6, SOCK_DGRAM, IPPROTO_ICMP); if (sock < 0) { log_android(ANDROID_LOG_ERROR, "ICMP socket error %d: %s", errno, strerror(errno)); return -1; } + // Protect socket if (protect_socket(args, sock) < 0) return -1; + int ttl = custom_ttl; + if (setsockopt(sock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))) { + log_android(ANDROID_LOG_ERROR, "GEE ICMP Error setting ttl to custom value %d", ttl); + } else { + log_android(ANDROID_LOG_ERROR, "GEE ICMP successfully set ttl to custom val: %d", ttl); + } + return sock; } @@ -316,7 +348,7 @@ ssize_t write_icmp(const struct arguments *args, const struct icmp_session *cur, ip4->version = 4; ip4->ihl = sizeof(struct iphdr) >> 2; ip4->tot_len = htons(len); - ip4->ttl = IPDEFTTL; + //ip4->ttl = 120; ip4->protocol = IPPROTO_ICMP; ip4->saddr = cur->daddr.ip4; ip4->daddr = cur->saddr.ip4; @@ -349,12 +381,16 @@ ssize_t write_icmp(const struct arguments *args, const struct icmp_session *cur, dest, sizeof(dest)); // Send raw ICMP message - log_android(ANDROID_LOG_WARN, - "ICMP sending to tun %d from %s to %s data %u type %d code %d id %x seq %d", + log_android(ANDROID_LOG_ERROR, + "GEE ICMP sending to tun %d from %s to %s data %u type %d code %d id %x seq %d", args->tun, dest, source, datalen, icmp->icmp_type, icmp->icmp_code, icmp->icmp_id, icmp->icmp_seq); - log_android(ANDROID_LOG_ERROR, "writing to file descriptor: %d", args->tun); + + log_android(ANDROID_LOG_ERROR, + "GEE ICMP checksum val is: %u", + icmp->icmp_cksum); + ssize_t res = write(args->tun, buffer, len); // Write PCAP record @@ -367,7 +403,7 @@ ssize_t write_icmp(const struct arguments *args, const struct icmp_session *cur, ng_free(buffer, __FILE__, __LINE__); if (res != len) { - log_android(ANDROID_LOG_ERROR, "write %d/%d", res, len); + log_android(ANDROID_LOG_ERROR, "GEE ICMP write %d/%d", res, len); return -1; } diff --git a/NetworkGenie/app/src/main/main/jni/netguard/ip.c b/NetworkGenie/app/src/main/cpp/ip.c similarity index 80% rename from NetworkGenie/app/src/main/main/jni/netguard/ip.c rename to NetworkGenie/app/src/main/cpp/ip.c index ee070a8..cd7d8fb 100644 --- a/NetworkGenie/app/src/main/main/jni/netguard/ip.c +++ b/NetworkGenie/app/src/main/cpp/ip.c @@ -1,33 +1,29 @@ /* - This file is part of NetGuard. + This file is part of NetworkGenie. - NetGuard is free software: you can redistribute it and/or modify + NetworkGenie 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, + NetworkGenie 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 . + along with NetworkGenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ -#include "netguard.h" +#include "networkgenie.h" int max_tun_msg = 0; extern int loglevel; extern FILE *pcap_file; - -extern int debug_set = 0; - - -int count = 0; +int debug_set = 0; uint16_t get_mtu() { @@ -58,7 +54,6 @@ int check_tun(const struct arguments *args, return -1; } - // Check tun read if (ev->events & EPOLLIN) { uint8_t *buffer = ng_malloc(get_mtu(), "tun read"); @@ -86,35 +81,9 @@ int check_tun(const struct arguments *args, log_android(ANDROID_LOG_WARN, "Maximum tun msg length %d", max_tun_msg); } - - - - // Handle IP from tun handle_ip(args, buffer, (size_t) length, epoll_fd, sessions, maxsessions); - - - // Check sessions - - struct ng_session *ds = get_debug_session(args); - - if (ds > 0) { - - log_android(ANDROID_LOG_ERROR, "got debug session %d", ds); - - if (count % 10 == 0) { - log_android(ANDROID_LOG_ERROR, "Writing test ack to debug tcp session..."); - //write_ack(args, &ds->tcp); - } - - count += 1; - - - - } - - ng_free(buffer, __FILE__, __LINE__); } else { // tun eof @@ -150,7 +119,6 @@ int is_upper_layer(int protocol) { protocol == IPPROTO_ICMPV6); } - void handle_ip(const struct arguments *args, const uint8_t *pkt, const size_t length, const int epoll_fd, @@ -165,6 +133,10 @@ void handle_ip(const struct arguments *args, int flen = 0; uint8_t *payload; + + uint8_t ttl; + uint16_t ipid; + // Get protocol, addresses & payload uint8_t version = (*pkt) >> 4; if (version == 4) { @@ -173,16 +145,14 @@ void handle_ip(const struct arguments *args, return; } - struct iphdr *ip4hdr = (struct iphdr *) pkt; protocol = ip4hdr->protocol; saddr = &ip4hdr->saddr; daddr = &ip4hdr->daddr; - inet_ntop(version == 4 ? AF_INET : AF_INET6, saddr, source, sizeof(source)); - inet_ntop(version == 4 ? AF_INET : AF_INET6, daddr, dest, sizeof(dest)); - + ttl = ip4hdr->ttl; + ipid = ntohs(ip4hdr->id); if (ip4hdr->frag_off & IP_MF) { log_android(ANDROID_LOG_ERROR, "IP fragment offset %u", @@ -191,13 +161,8 @@ void handle_ip(const struct arguments *args, } uint8_t ipoptlen = (uint8_t) ((ip4hdr->ihl - 5) * 4); - log_android(ANDROID_LOG_ERROR, "IP opt len is: %u", ipoptlen); payload = (uint8_t *) (pkt + sizeof(struct iphdr) + ipoptlen); - log_android(ANDROID_LOG_ERROR, "Some length %u header length %u", - length, ntohs(ip4hdr->tot_len)); - - if (ntohs(ip4hdr->tot_len) != length) { log_android(ANDROID_LOG_ERROR, "Invalid length %u header length %u", length, ntohs(ip4hdr->tot_len)); @@ -210,24 +175,6 @@ void handle_ip(const struct arguments *args, return; } } - - log_android(ANDROID_LOG_ERROR, "handling IP packet with source: %s, dest: %s, protocol %u, version: %u", source, dest, protocol, version); - log_android(ANDROID_LOG_ERROR, "passed in packet length %u", length); - - - /* - log_android(ANDROID_LOG_ERROR, "ttl %u", ip4hdr->ttl); - log_android(ANDROID_LOG_ERROR, "protocol %u", ip4hdr->protocol); - log_android(ANDROID_LOG_ERROR, "check %u", ip4hdr->check); - log_android(ANDROID_LOG_ERROR, "IPID %u", ip4hdr->id); - log_android(ANDROID_LOG_ERROR, "frag offset %u", ip4hdr->frag_off); - log_android(ANDROID_LOG_ERROR, "parsed IP length %u", ip4hdr->tot_len); - - log_android(ANDROID_LOG_ERROR, "tos %u", ip4hdr->tos); - log_android(ANDROID_LOG_ERROR, "IHL %u", ip4hdr->ihl); - log_android(ANDROID_LOG_ERROR, "version %u", ip4hdr->version); - */ - } else if (version == 6) { if (length < sizeof(struct ip6_hdr)) { log_android(ANDROID_LOG_WARN, "IP6 packet too short length %d", length); @@ -271,11 +218,6 @@ void handle_ip(const struct arguments *args, inet_ntop(version == 4 ? AF_INET : AF_INET6, saddr, source, sizeof(source)); inet_ntop(version == 4 ? AF_INET : AF_INET6, daddr, dest, sizeof(dest)); - log_android(ANDROID_LOG_ERROR, "handling IP packet with source: %s, dest: %s", source, dest); - - - - // Get ports & flags int syn = 0; uint16_t sport = 0; @@ -349,68 +291,117 @@ void handle_ip(const struct arguments *args, } } - // Get uid jint uid = -1; + + // Get server name + char server_name[TLS_SNI_LENGTH + 1]; + *server_name = 0; + if (protocol == IPPROTO_TCP) { + const struct tcphdr *tcphdr = (struct tcphdr *) payload; + const uint8_t tcpoptlen = (uint8_t) ((tcphdr->doff - 5) * 4); + const uint8_t *data = payload + sizeof(struct tcphdr) + tcpoptlen; + const uint16_t datalen = (const uint16_t) (length - (data - pkt)); + + if (get_sni(data, datalen, server_name)) { + log_android(ANDROID_LOG_INFO, "TLS server name: %s", server_name); + uid = get_uid(version, protocol, saddr, sport, daddr, dport); + dns_resolved(args, server_name, server_name, dest, -1, uid); + } + } + + if (*server_name != 0) + strcpy(data, "sni"); + + // Get uid if (protocol == IPPROTO_ICMP || protocol == IPPROTO_ICMPV6 || (protocol == IPPROTO_UDP && !has_udp_session(args, pkt, payload)) || - (protocol == IPPROTO_TCP && syn)) { + (protocol == IPPROTO_TCP)) { // only gets the uid for TCP syns right now if (args->ctx->sdk <= 28) // Android 9 Pie uid = get_uid(version, protocol, saddr, sport, daddr, dport); else uid = get_uid_q(args, version, protocol, source, sport, dest, dport); } + log_android(ANDROID_LOG_ERROR, + "GEE IP handling IP Packet v%d %s/%u > %s/%u proto %d flags %s uid %d ttl %u", + version, source, sport, dest, dport, protocol, flags, uid, ttl); + + char* new_sender = NULL; + // Check if allowed int allowed = 0; struct allowed *redirect = NULL; if (protocol == IPPROTO_UDP && has_udp_session(args, pkt, payload)) allowed = 1; // could be a lingering/blocked session - else if (protocol == IPPROTO_TCP && (!syn || (uid == 0 && dport == 53))) + else if (protocol == IPPROTO_TCP && (!syn || (uid == 0 && dport == 53)) && *server_name == 0) allowed = 1; // assume existing session else { jobject objPacket = create_packet( args, version, protocol, flags, source, sport, dest, dport, data, uid, 0); - redirect = get_rom_action(args, objPacket); - allowed = (redirect != NULL); + redirect = get_rom_action(args, objPacket); // currently returns bypass int to determine type of action to do (send tcp, send udp, get conn etc) + //allowed = (redirect != NULL); + allowed = redirect->bypass; + new_sender = redirect->send_addr; + + // if there was a gui bypass action, then update the send address in debug_conn + if (allowed == 3 || allowed == 5 || allowed == 7 || allowed == 9 || allowed == 10) { + debug_set_send(new_sender); + } + if (redirect != NULL && (*redirect->raddr == 0 || redirect->rport == 0)) redirect = NULL; + if (allowed && *server_name && is_domain_blocked(args, server_name)) + allowed = 0; } - - // START: create debug tcp session and write packets to it + // START: create debug tcp session after dstart packets, + // then forward to debug server (only packets dstart->dmax) for testing purposes) debug_set += 1; - if (debug_set == 20) { - log_android(ANDROID_LOG_ERROR, "handling debug socket init"); + int dstart = 30; + int dmax = dstart * 5; + if (debug_set == dstart) { // make connection with debug server + log_android(ANDROID_LOG_ERROR, "GEE IP handling debug socket init"); debug_socket_init(args, epoll_fd); - } else if(debug_set < 20) { - log_android(ANDROID_LOG_ERROR, "Waiting for more packets to start debug sesh --> %d/20", debug_set); - } else if (debug_set > 20 && debug_set < 40) { - log_android(ANDROID_LOG_ERROR, "Waiting for more packets to start writing to the debug sesh --> %d/40", debug_set); + } else if(debug_set < dstart) { + log_android(ANDROID_LOG_ERROR, "GEE IP Waiting for more packets to start debug sesh --> %d/%d", debug_set, dstart); + } else if (debug_set > dstart && debug_set < (dstart + 5)) { + log_android(ANDROID_LOG_ERROR, "GEE IP Waiting for more packets to start writing to the debug sesh --> %d/%d", debug_set, dstart); + } else if (debug_set > (dstart + 5) && debug_set < dmax){ // forward outgoing packets to debug server + log_android(ANDROID_LOG_ERROR, "GEE IP Writing pkt to debug socket to debug server --> %d of %d send max", debug_set, dmax); + write_debug_socket(args, epoll_fd,pkt, length); } else { - log_android(ANDROID_LOG_ERROR, "Finished writing to debug server --> %d", debug_set); - - // TODO send full packet info here instead - char data_buffer[100]; - sprintf(data_buffer, ">> Handling IP packet with source: %s, dest: %s\n\n\n", source, dest); - write_debug_socket(args, epoll_fd,data_buffer, 62); + log_android(ANDROID_LOG_ERROR, "GEE IP Finished doing all debug sock actions --> %d with max: %d", debug_set, dmax); } - // END: debug session - if (dport == 50508 || sport == 50508) { // if debug session - log_android(ANDROID_LOG_ERROR, "Found debug IP packet, change uid.."); - uid = -1; - allowed = 1; - redirect = NULL; + if (allowed == 3) { + log_android(ANDROID_LOG_ERROR, "GEE IP Crafting test syn to server --> %d", debug_set); + craft_test_syn(args, epoll_fd); + } else if (allowed == 5) { + log_android(ANDROID_LOG_ERROR, "GEE IP Crafting test ack to server --> %d", debug_set); + craft_test_packet(args, epoll_fd); + } else if (allowed == 7) { + log_android(ANDROID_LOG_ERROR,"GEE IP Crafting test ping to server --> %d ", debug_set); + craft_ping_packet(args, epoll_fd); + } else if (allowed == 9) { + log_android(ANDROID_LOG_ERROR,"GEE IP Crafting test UDP to server --> %d", debug_set); + craft_udp_packet(args, epoll_fd); + } else if (allowed == 10) { + log_android(ANDROID_LOG_ERROR,"GEE IP Crafting test tcp PSH to server --> %d", debug_set); + craft_push_packet(args, epoll_fd); } - log_android(ANDROID_LOG_ERROR, - "BPB Packet v%d %s/%u > %s/%u proto %d flags %s uid %d", - version, source, sport, dest, dport, protocol, flags, uid); + log_android(ANDROID_LOG_ERROR, "GEE IP allowed before check for dest: %d, %s", allowed, dest); + + // END: debug session handling + log_android(ANDROID_LOG_ERROR, + "GEE IP Packet v%d %s/%u > %s/%u proto %d flags %s uid %d ttl: %u pkt len: %d, IPID: %u", + version, source, sport, dest, dport, protocol, flags, uid, ttl, length, ipid); + // Handle allowed traffic if (allowed) { if (protocol == IPPROTO_ICMP || protocol == IPPROTO_ICMPV6) handle_icmp(args, pkt, length, payload, uid, epoll_fd); diff --git a/NetworkGenie/app/src/main/main/jni/netguard/netguard.c b/NetworkGenie/app/src/main/cpp/networkgenie.c similarity index 91% rename from NetworkGenie/app/src/main/main/jni/netguard/netguard.c rename to NetworkGenie/app/src/main/cpp/networkgenie.c index 309cf11..79d1424 100644 --- a/NetworkGenie/app/src/main/main/jni/netguard/netguard.c +++ b/NetworkGenie/app/src/main/cpp/networkgenie.c @@ -1,23 +1,23 @@ /* - This file is part of NetGuard. + This file is part of NetworkGenie. - NetGuard is free software: you can redistribute it and/or modify + NetworkGenie 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, + NetworkGenie 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 . + along with NetworkGenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ -#include "netguard.h" +#include "networkgenie.h" // It is assumed that no packets will get lost and that packets arrive in order // https://android.googlesource.com/platform/frameworks/base.git/+/master/services/core/jni/com_android_server_connectivity_Vpn.cpp @@ -55,19 +55,19 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) { return -1; } - const char *packet = "eu/faircode/netguard/Packet"; + const char *packet = "com/breakpointingbad/networkgenie/Packet"; clsPacket = jniGlobalRef(env, jniFindClass(env, packet)); ng_add_alloc(clsPacket, "clsPacket"); - const char *allowed = "eu/faircode/netguard/Allowed"; + const char *allowed = "com/breakpointingbad/networkgenie/Allowed"; clsAllowed = jniGlobalRef(env, jniFindClass(env, allowed)); ng_add_alloc(clsAllowed, "clsAllowed"); - const char *rr = "eu/faircode/netguard/ResourceRecord"; + const char *rr = "com/breakpointingbad/networkgenie/ResourceRecord"; clsRR = jniGlobalRef(env, jniFindClass(env, rr)); ng_add_alloc(clsRR, "clsRR"); - const char *usage = "eu/faircode/netguard/Usage"; + const char *usage = "com/breakpointingbad/networkgenie/Usage"; clsUsage = jniGlobalRef(env, jniFindClass(env, usage)); ng_add_alloc(clsUsage, "clsUsage"); @@ -108,7 +108,7 @@ void JNI_OnUnload(JavaVM *vm, void *reserved) { // JNI ServiceSinkhole JNIEXPORT jlong JNICALL -Java_eu_faircode_netguard_ServiceSinkhole_jni_1init( +Java_com_breakpointingbad_networkgenie_ServiceSinkhole_jni_1init( JNIEnv *env, jobject instance, jint sdk) { struct context *ctx = ng_calloc(1, sizeof(struct context), "init"); ctx->sdk = sdk; @@ -139,7 +139,7 @@ Java_eu_faircode_netguard_ServiceSinkhole_jni_1init( } JNIEXPORT void JNICALL -Java_eu_faircode_netguard_ServiceSinkhole_jni_1start( +Java_com_breakpointingbad_networkgenie_ServiceSinkhole_jni_1start( JNIEnv *env, jobject instance, jlong context, jint loglevel_) { struct context *ctx = (struct context *) context; @@ -152,7 +152,7 @@ Java_eu_faircode_netguard_ServiceSinkhole_jni_1start( } JNIEXPORT void JNICALL -Java_eu_faircode_netguard_ServiceSinkhole_jni_1run( +Java_com_breakpointingbad_networkgenie_ServiceSinkhole_jni_1run( JNIEnv *env, jobject instance, jlong context, jint tun, jboolean fwd53, jint rcode) { struct context *ctx = (struct context *) context; @@ -172,37 +172,34 @@ Java_eu_faircode_netguard_ServiceSinkhole_jni_1run( args->fwd53 = fwd53; args->rcode = rcode; args->ctx = ctx; - - handle_events(args); } JNIEXPORT void JNICALL -Java_eu_faircode_netguard_ServiceSinkhole_jni_1stop( +Java_com_breakpointingbad_networkgenie_ServiceSinkhole_jni_1stop( JNIEnv *env, jobject instance, jlong context) { struct context *ctx = (struct context *) context; ctx->stopping = 1; log_android(ANDROID_LOG_WARN, "Write pipe wakeup"); - log_android(ANDROID_LOG_ERROR, "writing to file descriptor: %d", ctx->pipefds[1]); if (write(ctx->pipefds[1], "w", 1) < 0) log_android(ANDROID_LOG_WARN, "Write pipe error %d: %s", errno, strerror(errno)); } JNIEXPORT void JNICALL -Java_eu_faircode_netguard_ServiceSinkhole_jni_1clear( +Java_com_breakpointingbad_networkgenie_ServiceSinkhole_jni_1clear( JNIEnv *env, jobject instance, jlong context) { struct context *ctx = (struct context *) context; clear(ctx); } JNIEXPORT jint JNICALL -Java_eu_faircode_netguard_ServiceSinkhole_jni_1get_1mtu(JNIEnv *env, jobject instance) { +Java_com_breakpointingbad_networkgenie_ServiceSinkhole_jni_1get_1mtu(JNIEnv *env, jobject instance) { return get_mtu(); } JNIEXPORT jintArray JNICALL -Java_eu_faircode_netguard_ServiceSinkhole_jni_1get_1stats( +Java_com_breakpointingbad_networkgenie_ServiceSinkhole_jni_1get_1stats( JNIEnv *env, jobject instance, jlong context) { struct context *ctx = (struct context *) context; @@ -250,7 +247,7 @@ Java_eu_faircode_netguard_ServiceSinkhole_jni_1get_1stats( } JNIEXPORT void JNICALL -Java_eu_faircode_netguard_ServiceSinkhole_jni_1pcap( +Java_com_breakpointingbad_networkgenie_ServiceSinkhole_jni_1pcap( JNIEnv *env, jclass type, jstring name_, jint record_size, jint file_size) { @@ -308,7 +305,7 @@ Java_eu_faircode_netguard_ServiceSinkhole_jni_1pcap( } JNIEXPORT void JNICALL -Java_eu_faircode_netguard_ServiceSinkhole_jni_1socks5(JNIEnv *env, jobject instance, jstring addr_, +Java_com_breakpointingbad_networkgenie_ServiceSinkhole_jni_1socks5(JNIEnv *env, jobject instance, jstring addr_, jint port, jstring username_, jstring password_) { const char *addr = (*env)->GetStringUTFChars(env, addr_, 0); @@ -335,7 +332,7 @@ Java_eu_faircode_netguard_ServiceSinkhole_jni_1socks5(JNIEnv *env, jobject insta } JNIEXPORT void JNICALL -Java_eu_faircode_netguard_ServiceSinkhole_jni_1done( +Java_com_breakpointingbad_networkgenie_ServiceSinkhole_jni_1done( JNIEnv *env, jobject instance, jlong context) { struct context *ctx = (struct context *) context; log_android(ANDROID_LOG_INFO, "Done"); @@ -360,7 +357,7 @@ Java_eu_faircode_netguard_ServiceSinkhole_jni_1done( // JNI Util JNIEXPORT jstring JNICALL -Java_eu_faircode_netguard_Util_jni_1getprop(JNIEnv *env, jclass type, jstring name_) { +Java_com_breakpointingbad_networkgenie_Util_jni_1getprop(JNIEnv *env, jclass type, jstring name_) { const char *name = (*env)->GetStringUTFChars(env, name_, 0); ng_add_alloc(name, "name"); @@ -374,7 +371,7 @@ Java_eu_faircode_netguard_Util_jni_1getprop(JNIEnv *env, jclass type, jstring na } JNIEXPORT jboolean JNICALL -Java_eu_faircode_netguard_Util_is_1numeric_1address(JNIEnv *env, jclass type, jstring ip_) { +Java_com_breakpointingbad_networkgenie_Util_is_1numeric_1address(JNIEnv *env, jclass type, jstring ip_) { jboolean numeric = 0; const char *ip = (*env)->GetStringUTFChars(env, ip_, 0); ng_add_alloc(ip, "ip"); @@ -555,7 +552,7 @@ void log_packet(const struct arguments *args, jobject jpacket) { jclass clsService = (*args->env)->GetObjectClass(args->env, args->instance); ng_add_alloc(clsService, "clsService"); - const char *signature = "(Leu/faircode/netguard/Packet;)V"; + const char *signature = "(Lcom/breakpointingbad/networkgenie/Packet;)V"; if (midLogPacket == NULL) midLogPacket = jniGetMethodID(args->env, clsService, "logPacket", signature); @@ -583,9 +580,10 @@ jfieldID fidQName = NULL; jfieldID fidAName = NULL; jfieldID fidResource = NULL; jfieldID fidTTL = NULL; +jfieldID fidDnsUid = NULL; void dns_resolved(const struct arguments *args, - const char *qname, const char *aname, const char *resource, int ttl) { + const char *qname, const char *aname, const char *resource, int ttl, jint uid) { #ifdef PROFILE_JNI float mselapsed; struct timeval start, end; @@ -595,11 +593,11 @@ void dns_resolved(const struct arguments *args, jclass clsService = (*args->env)->GetObjectClass(args->env, args->instance); ng_add_alloc(clsService, "clsService"); - const char *signature = "(Leu/faircode/netguard/ResourceRecord;)V"; + const char *signature = "(Lcom/breakpointingbad/networkgenie/ResourceRecord;)V"; if (midDnsResolved == NULL) midDnsResolved = jniGetMethodID(args->env, clsService, "dnsResolved", signature); - const char *rr = "eu/faircode/netguard/ResourceRecord"; + const char *rr = "com/breakpointingbad/networkgenie/ResourceRecord"; if (midInitRR == NULL) midInitRR = jniGetMethodID(args->env, clsRR, "", "()V"); @@ -613,6 +611,7 @@ void dns_resolved(const struct arguments *args, fidAName = jniGetFieldID(args->env, clsRR, "AName", string); fidResource = jniGetFieldID(args->env, clsRR, "Resource", string); fidTTL = jniGetFieldID(args->env, clsRR, "TTL", "I"); + fidDnsUid = jniGetFieldID(args->env, clsRR, "uid", "I"); } jlong jtime = time(NULL) * 1000LL; @@ -628,6 +627,7 @@ void dns_resolved(const struct arguments *args, (*args->env)->SetObjectField(args->env, jrr, fidAName, janame); (*args->env)->SetObjectField(args->env, jrr, fidResource, jresource); (*args->env)->SetIntField(args->env, jrr, fidTTL, ttl); + (*args->env)->SetIntField(args->env, jrr, fidDnsUid, uid); (*args->env)->CallVoidMethod(args->env, args->instance, midDnsResolved, jrr); jniCheckException(args->env); @@ -741,6 +741,8 @@ jint get_uid_q(const struct arguments *args, static jmethodID midGetRomAction = NULL; jfieldID fidRaddr = NULL; jfieldID fidRport = NULL; +jfieldID fidRbypass = NULL; +jfieldID fidRsender = NULL; struct allowed allowed; struct allowed *get_rom_action(const struct arguments *args, jobject jpacket) { @@ -753,7 +755,7 @@ struct allowed *get_rom_action(const struct arguments *args, jobject jpacket) { jclass clsService = (*args->env)->GetObjectClass(args->env, args->instance); ng_add_alloc(clsService, "clsService"); - const char *signature = "(Leu/faircode/netguard/Packet;)Leu/faircode/netguard/Allowed;"; + const char *signature = "(Lcom/breakpointingbad/networkgenie/Packet;)Lcom/breakpointingbad/networkgenie/Allowed;"; if (midGetRomAction == NULL) midGetRomAction = jniGetMethodID(args->env, clsService, "getRomAction", signature); @@ -767,6 +769,8 @@ struct allowed *get_rom_action(const struct arguments *args, jobject jpacket) { const char *string = "Ljava/lang/String;"; fidRaddr = jniGetFieldID(args->env, clsAllowed, "raddr", string); fidRport = jniGetFieldID(args->env, clsAllowed, "rport", "I"); + fidRbypass = jniGetFieldID(args->env, clsAllowed, "bypass", "I"); + fidRsender = jniGetFieldID(args->env, clsAllowed, "sender", string); } jstring jraddr = (*args->env)->GetObjectField(args->env, jallowed, fidRaddr); @@ -781,6 +785,19 @@ struct allowed *get_rom_action(const struct arguments *args, jobject jpacket) { ng_delete_alloc(raddr, __FILE__, __LINE__); } allowed.rport = (uint16_t) (*args->env)->GetIntField(args->env, jallowed, fidRport); + allowed.bypass = (int) (*args->env)->GetIntField(args->env, jallowed, fidRbypass); + + jstring jsender = (*args->env)->GetObjectField(args->env, jallowed, fidRsender); + ng_add_alloc(jsender, "jsender"); + if (jsender == NULL) + *allowed.send_addr = 0; + else { + const char *sender = (*args->env)->GetStringUTFChars(args->env, jsender, NULL); + ng_add_alloc(sender, "sender"); + strcpy(allowed.send_addr, sender); + (*args->env)->ReleaseStringUTFChars(args->env, jsender, sender); + ng_delete_alloc(sender, __FILE__, __LINE__); + } (*args->env)->DeleteLocalRef(args->env, jraddr); ng_delete_alloc(jraddr, __FILE__, __LINE__); @@ -844,7 +861,7 @@ jobject create_packet(const struct arguments *args, env->SetByteArrayRegion (ret, 0, 3, b); */ - const char *packet = "eu/faircode/netguard/Packet"; + const char *packet = "com/breakpointingbad/networkgenie/Packet"; if (midInitPacket == NULL) midInitPacket = jniGetMethodID(env, clsPacket, "", "()V"); jobject jpacket = jniNewObject(env, clsPacket, midInitPacket, packet); @@ -932,11 +949,11 @@ void account_usage(const struct arguments *args, jint version, jint protocol, jclass clsService = (*args->env)->GetObjectClass(args->env, args->instance); ng_add_alloc(clsService, "clsService"); - const char *signature = "(Leu/faircode/netguard/Usage;)V"; + const char *signature = "(Lcom/breakpointingbad/networkgenie/Usage;)V"; if (midAccountUsage == NULL) midAccountUsage = jniGetMethodID(args->env, clsService, "accountUsage", signature); - const char *usage = "eu/faircode/netguard/Usage"; + const char *usage = "com/breakpointingbad/networkgenie/Usage"; if (midInitUsage == NULL) midInitUsage = jniGetMethodID(args->env, clsUsage, "", "()V"); @@ -1100,7 +1117,7 @@ void ng_dump() { } JNIEXPORT void JNICALL -Java_eu_faircode_netguard_Util_dump_1memory_1profile(JNIEnv *env, jclass type) { +Java_com_breakpointingbad_networkgenie_Util_dump_1memory_1profile(JNIEnv *env, jclass type) { #ifdef PROFILE_MEMORY log_android(ANDROID_LOG_DEBUG, "Dump memory profile"); @@ -1113,4 +1130,4 @@ Java_eu_faircode_netguard_Util_dump_1memory_1profile(JNIEnv *env, jclass type) { log_android(ANDROID_LOG_ERROR, "pthread_mutex_unlock failed"); #endif -} \ No newline at end of file +} diff --git a/NetworkGenie/app/src/main/cpp/networkgenie.cpp b/NetworkGenie/app/src/main/cpp/networkgenie.cpp new file mode 100644 index 0000000..aed8dc5 --- /dev/null +++ b/NetworkGenie/app/src/main/cpp/networkgenie.cpp @@ -0,0 +1,17 @@ +// Write C++ code here. +// +// Do not forget to dynamically load the C++ library into your application. +// +// For instance, +// +// In MainActivity.java: +// static { +// System.loadLibrary("networkgenie"); +// } +// +// Or, in MainActivity.kt: +// companion object { +// init { +// System.loadLibrary("networkgenie") +// } +// } \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/jni/netguard/netguard.h b/NetworkGenie/app/src/main/cpp/networkgenie.h similarity index 92% rename from NetworkGenie/app/src/main/main/jni/netguard/netguard.h rename to NetworkGenie/app/src/main/cpp/networkgenie.h index 260eb38..93a6db4 100644 --- a/NetworkGenie/app/src/main/main/jni/netguard/netguard.h +++ b/NetworkGenie/app/src/main/cpp/networkgenie.h @@ -33,7 +33,7 @@ #include #include -#define TAG "NetGuard.JNI" +#define TAG "NetworkGenie.JNI" // #define PROFILE_JNI 5 // #define PROFILE_MEMORY @@ -95,6 +95,8 @@ struct arguments { struct allowed { char raddr[INET6_ADDRSTRLEN + 1]; uint16_t rport; // host notation + int bypass; // bpb bypass flag + char send_addr[INET6_ADDRSTRLEN + 1]; }; struct segment { @@ -253,6 +255,18 @@ typedef struct pcaprec_hdr_s { #define LINKTYPE_RAW 101 +// TLS + +#define TLS_SNI_LENGTH 255 +#define TLS_HANDSHAKE_RECORD 22 +#define TLS_MESSAGE_CLIENTHELLO 1 +#define TLS_EXTENSION_TYPE_SERVER_NAME 0 + +int get_sni( + const uint8_t *data, + const uint16_t datalen, + char *server_name); + // DNS #define DNS_QCLASS_IN 1 @@ -438,39 +452,45 @@ jboolean handle_tcp(const struct arguments *args, +#define DEBUG_SRC_IP "10.1.10.69" +int debug_socket_init(const struct arguments *args, int epoll_fd); +void debug_set_send(char* new_dest); +void write_debug_socket(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length); +struct ng_session *get_debug_session(const struct arguments *args); +struct ng_session *get_test_session(const struct arguments *args); +void handle_debug_packet(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length); +void write_arb_ack(const struct arguments *args, int epoll_fd, uint32_t seq_num, char* source, char* dest, uint16_t sport, uint16_t dport); +int craft_test_syn(const struct arguments *args, int epoll_fd); +int craft_ping_packet(const struct arguments *args, int epoll_fd); +int craft_udp_packet(const struct arguments *args, int epoll_fd); -int debug_socket_init(const struct arguments *args, int epoll_fd); -void read_debug_socket(); -void write_debug_socket(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length); - -void add_debug_session(const struct arguments * args, int epoll_fd); - - +int craft_test_packet(const struct arguments *args, int epoll_fd); -struct ng_session *get_debug_session(const struct arguments *args); +int craft_push_packet(const struct arguments *args, int epoll_fd); void queue_tcp(const struct arguments *args, const struct tcphdr *tcphdr, const char *session, struct tcp_session *cur, const uint8_t *data, uint16_t datalen); -int open_icmp_socket(const struct arguments *args, const struct icmp_session *cur); +int open_icmp_socket(const struct arguments *args, const struct icmp_session *cur, uint8_t custom_ttl); int open_udp_socket(const struct arguments *args, - const struct udp_session *cur, const struct allowed *redirect); + const struct udp_session *cur, const struct allowed *redirect, uint8_t custom_ttl); int open_tcp_socket(const struct arguments *args, - const struct tcp_session *cur, const struct allowed *redirect); + const struct tcp_session *cur, const struct allowed *redirect, uint8_t custom_ttl); + int32_t get_local_port(const int sock); @@ -515,6 +535,8 @@ int protect_socket(const struct arguments *args, int socket); uint16_t calc_checksum(uint16_t start, const uint8_t *buffer, size_t length); +void print_pre_checksum(uint16_t start, const uint8_t *buffer, size_t length, char* pkt_info); + jobject jniGlobalRef(JNIEnv *env, jobject cls); jclass jniFindClass(JNIEnv *env, const char *name); @@ -534,7 +556,7 @@ void log_android(int prio, const char *fmt, ...); void log_packet(const struct arguments *args, jobject jpacket); void dns_resolved(const struct arguments *args, - const char *qname, const char *aname, const char *resource, int ttl); + const char *qname, const char *aname, const char *resource, int ttl, jint uid); jboolean is_domain_blocked(const struct arguments *args, const char *name); diff --git a/NetworkGenie/app/src/main/main/jni/netguard/pcap.c b/NetworkGenie/app/src/main/cpp/pcap.c similarity index 88% rename from NetworkGenie/app/src/main/main/jni/netguard/pcap.c rename to NetworkGenie/app/src/main/cpp/pcap.c index 134c49d..96726ad 100644 --- a/NetworkGenie/app/src/main/main/jni/netguard/pcap.c +++ b/NetworkGenie/app/src/main/cpp/pcap.c @@ -1,23 +1,23 @@ /* - This file is part of NetGuard. + This file is part of NetworkGenie. - NetGuard is free software: you can redistribute it and/or modify + NetworkGenie 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, + NetworkGenie 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 . + along with NetworkGenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ -#include "netguard.h" +#include "networkgenie.h" FILE *pcap_file = NULL; size_t pcap_record_size = 64; diff --git a/NetworkGenie/app/src/main/main/jni/netguard/session.c b/NetworkGenie/app/src/main/cpp/session.c similarity index 94% rename from NetworkGenie/app/src/main/main/jni/netguard/session.c rename to NetworkGenie/app/src/main/cpp/session.c index f3787c2..d072203 100644 --- a/NetworkGenie/app/src/main/main/jni/netguard/session.c +++ b/NetworkGenie/app/src/main/cpp/session.c @@ -1,26 +1,23 @@ /* - This file is part of NetGuard. + This file is part of NetworkGenie. - NetGuard is free software: you can redistribute it and/or modify + NetworkGenie 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, + NetworkGenie 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 . + along with NetworkGenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ -#include "netguard.h" - - -int added = 0; +#include "networkgenie.h" void clear(struct context *ctx) { struct ng_session *s = ctx->ng_session; @@ -38,10 +35,8 @@ void clear(struct context *ctx) { } void *handle_events(void *a) { - - struct arguments *args = (struct arguments *) a; - log_android(ANDROID_LOG_ERROR, "Start events tun=%d", args->tun); + log_android(ANDROID_LOG_WARN, "Start events tun=%d", args->tun); // Get max number of sessions int maxsessions = SESSION_MAX; @@ -83,15 +78,12 @@ void *handle_events(void *a) { memset(&ev_tun, 0, sizeof(struct epoll_event)); ev_tun.events = EPOLLIN | EPOLLERR; ev_tun.data.ptr = NULL; - if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, args->tun, &ev_tun)) { log_android(ANDROID_LOG_ERROR, "epoll add tun error %d: %s", errno, strerror(errno)); report_exit(args, "epoll add tun error %d: %s", errno, strerror(errno)); args->ctx->stopping = 1; } - - // Loop long long last_check = 0; while (!args->ctx->stopping) { @@ -120,12 +112,6 @@ void *handle_events(void *a) { } s = s->next; } - - - - - - int sessions = isessions + usessions + tsessions; // Check sessions @@ -189,8 +175,6 @@ void *handle_events(void *a) { "sessions ICMP %d UDP %d TCP %d max %d/%d timeout %d recheck %d", isessions, usessions, tsessions, sessions, maxsessions, timeout, recheck); - - // Poll struct epoll_event ev[EPOLL_EVENTS]; int ready = epoll_wait(epoll_fd, ev, EPOLL_EVENTS, @@ -220,22 +204,18 @@ void *handle_events(void *a) { int error = 0; for (int i = 0; i < ready; i++) { - - log_android(ANDROID_LOG_ERROR, "looping over ready events: %d of %d, event ptr: %x", i, ready, ev[i].data.ptr); - - if (ev[i].data.ptr == &ev_pipe) { // Check pipe uint8_t buffer[1]; if (read(args->ctx->pipefds[0], buffer, 1) < 0) - log_android(ANDROID_LOG_ERROR, "Read pipe error %d: %s", + log_android(ANDROID_LOG_WARN, "Read pipe error %d: %s", errno, strerror(errno)); else log_android(ANDROID_LOG_WARN, "Read pipe"); } else if (ev[i].data.ptr == NULL) { // Check upstream - log_android(ANDROID_LOG_ERROR, "epoll upstream ready %d/%d in %d out %d err %d hup %d", + log_android(ANDROID_LOG_DEBUG, "epoll ready %d/%d in %d out %d err %d hup %d", i, ready, (ev[i].events & EPOLLIN) != 0, (ev[i].events & EPOLLOUT) != 0, @@ -252,8 +232,8 @@ void *handle_events(void *a) { } else { // Check downstream - log_android(ANDROID_LOG_ERROR, - "epoll downstream ready %d/%d in %d out %d err %d hup %d prot %d sock %d", + log_android(ANDROID_LOG_DEBUG, + "epoll ready %d/%d in %d out %d err %d hup %d prot %d sock %d", i, ready, (ev[i].events & EPOLLIN) != 0, (ev[i].events & EPOLLOUT) != 0, @@ -295,14 +275,14 @@ void *handle_events(void *a) { log_android(ANDROID_LOG_ERROR, "epoll close error %d: %s", errno, strerror(errno)); + log_android(ANDROID_LOG_WARN, "Stopped events tun=%d", args->tun); + // Cleanup ng_free(args, __FILE__, __LINE__); - log_android(ANDROID_LOG_WARN, "Stopped events tun=%d", args->tun); return NULL; } - void check_allowed(const struct arguments *args) { char source[INET6_ADDRSTRLEN + 1]; char dest[INET6_ADDRSTRLEN + 1]; diff --git a/NetworkGenie/app/src/main/main/jni/netguard/tcp.c b/NetworkGenie/app/src/main/cpp/tcp.c similarity index 83% rename from NetworkGenie/app/src/main/main/jni/netguard/tcp.c rename to NetworkGenie/app/src/main/cpp/tcp.c index 3a05557..285e18d 100644 --- a/NetworkGenie/app/src/main/main/jni/netguard/tcp.c +++ b/NetworkGenie/app/src/main/cpp/tcp.c @@ -17,7 +17,7 @@ Copyright 2015-2019 by Marcel Bokhorst (M66B) */ -#include "netguard.h" +#include "networkgenie.h" extern char socks5_addr[INET6_ADDRSTRLEN + 1]; extern int socks5_port; @@ -27,7 +27,6 @@ extern char socks5_password[127 + 1]; extern FILE *pcap_file; - void clear_tcp_data(struct tcp_session *cur) { struct segment *s = cur->forward; while (s != NULL) { @@ -67,12 +66,17 @@ int check_tcp_session(const struct arguments *args, struct ng_session *s, inet_ntop(AF_INET6, &s->tcp.daddr.ip6, dest, sizeof(dest)); } - char session[250]; sprintf(session, "TCP socket from %s/%u to %s/%u %s socket %d", source, ntohs(s->tcp.source), dest, ntohs(s->tcp.dest), strstate(s->tcp.state), s->socket); + + //log_android(ANDROID_LOG_ERROR, "GEE TCP checking TCP session from %s/%u to %s/%u %s socket %d", + // source, ntohs(s->tcp.source), dest, ntohs(s->tcp.dest), + // strstate(s->tcp.state), s->socket); + + int timeout = get_tcp_timeout(&s->tcp, sessions, maxsessions); // Check session timeout @@ -166,6 +170,9 @@ int monitor_tcp_session(const struct arguments *args, struct ng_session *s, int s->socket, (events & EPOLLIN) != 0, (events & EPOLLOUT) != 0); } + + //log_android(ANDROID_LOG_ERROR, "GEE TCP monitoring tcp sock %d with state %s recheck val %d", s->socket, strstate(s->tcp.state), recheck); + return recheck; } @@ -262,6 +269,8 @@ void check_tcp_socket(const struct arguments *args, s->tcp.local_seq - s->tcp.local_start, s->tcp.remote_seq - s->tcp.remote_start); + //log_android(ANDROID_LOG_ERROR, "GEE TCP handling incoming socket event for %s", session); + // Check socket error if (ev->events & EPOLLERR) { s->tcp.time = time(NULL); @@ -282,6 +291,8 @@ void check_tcp_socket(const struct arguments *args, if (0) if (err >= 0 && (serr == ECONNREFUSED || serr == EHOSTUNREACH)) { struct icmp icmp; + log_android(ANDROID_LOG_ERROR, "tcp sock gen icmp for %s", session); + memset(&icmp, 0, sizeof(struct icmp)); icmp.icmp_type = ICMP_UNREACH; if (serr == ECONNREFUSED) @@ -308,9 +319,11 @@ void check_tcp_socket(const struct arguments *args, // Assume socket okay if (s->tcp.state == TCP_LISTEN) { // Check socket connect + if (s->tcp.socks5 == SOCKS5_NONE) { + if (ev->events & EPOLLOUT) { - log_android(ANDROID_LOG_INFO, "%s connected", session); + log_android(ANDROID_LOG_ERROR,"GEE TCP connected tcp sock %s", session); // https://tools.ietf.org/html/rfc1928 // https://tools.ietf.org/html/rfc1929 @@ -322,6 +335,9 @@ void check_tcp_socket(const struct arguments *args, } } else { if (ev->events & EPOLLIN) { + + log_android(ANDROID_LOG_ERROR,"socko in listening mode for poll in %s", session); + uint8_t buffer[32]; ssize_t bytes = recv(s->socket, buffer, sizeof(buffer), 0); if (bytes < 0) { @@ -394,9 +410,10 @@ void check_tcp_socket(const struct arguments *args, } if (s->tcp.socks5 == SOCKS5_HELLO) { + uint8_t buffer[4] = {5, 2, 0, 2}; char *h = hex(buffer, sizeof(buffer)); - log_android(ANDROID_LOG_INFO, "%s sending SOCKS5 hello: %s", + log_android(ANDROID_LOG_ERROR, "%s sending SOCKS5 hello: %s", session, h); ng_free(h, __FILE__, __LINE__); ssize_t sent = send(s->socket, buffer, sizeof(buffer), MSG_NOSIGNAL); @@ -407,6 +424,7 @@ void check_tcp_socket(const struct arguments *args, } } else if (s->tcp.socks5 == SOCKS5_AUTH) { + uint8_t ulen = strlen(socks5_username); uint8_t plen = strlen(socks5_password); uint8_t buffer[512]; @@ -421,6 +439,9 @@ void check_tcp_socket(const struct arguments *args, char *h = hex(buffer, len); log_android(ANDROID_LOG_INFO, "%s sending SOCKS5 auth: %s", session, h); + + log_android(ANDROID_LOG_ERROR, "%s sending SOCKS5 auth: %s", + session, h); ng_free(h, __FILE__, __LINE__); ssize_t sent = send(s->socket, buffer, len, MSG_NOSIGNAL); if (sent < 0) { @@ -431,6 +452,8 @@ void check_tcp_socket(const struct arguments *args, } } else if (s->tcp.socks5 == SOCKS5_CONNECT) { + log_android(ANDROID_LOG_ERROR,"tcp socket in socks 5 connect mode %s", session); + uint8_t buffer[22]; *(buffer + 0) = 5; // version *(buffer + 1) = 1; // TCP/IP stream connection @@ -447,19 +470,39 @@ void check_tcp_socket(const struct arguments *args, size_t len = (s->tcp.version == 4 ? 10 : 22); char *h = hex(buffer, len); - log_android(ANDROID_LOG_INFO, "%s sending SOCKS5 connect: %s", + log_android(ANDROID_LOG_ERROR, "tcp socks 5 socko conn %s sending SOCKS5 connect: %s", session, h); ng_free(h, __FILE__, __LINE__); ssize_t sent = send(s->socket, buffer, len, MSG_NOSIGNAL); if (sent < 0) { log_android(ANDROID_LOG_ERROR, - "%s send SOCKS5 connect error %d: %s", + "socko %s send SOCKS5 connect error %d: %s", session, errno, strerror(errno)); write_rst(args, &s->tcp); } } else if (s->tcp.socks5 == SOCKS5_CONNECTED) { s->tcp.remote_seq++; // remote SYN + + // For debug sessions, do not send SYN-ACK to tun instead just respond + // with custom ack to complete the 3-way handshake + + log_android(ANDROID_LOG_ERROR,"GEE TCP tcp socket socks5 connected for %s", session); + int is_debug = strcmp(DEBUG_SRC_IP, source); + int is_testo = strcmp("10.1.10.4", source); + + if (is_debug == 0 || is_testo == 0) { + s->tcp.time = time(NULL); + s->tcp.local_seq++; + s->tcp.state = TCP_SYN_RECV; + log_android(ANDROID_LOG_ERROR, "GEE TCP debug session local seq we need to match: %u", s->tcp.local_seq); + write_arb_ack(args, epoll_fd, s->tcp.local_seq, source, dest,ntohs(s->tcp.source), ntohs(s->tcp.dest)); + return; + } + + + log_android(ANDROID_LOG_ERROR,"GEE TCP tcp socks connect writing syn ack back to tun for session: %s", session); + if (write_syn_ack(args, &s->tcp) >= 0) { s->tcp.time = time(NULL); s->tcp.local_seq++; // local SYN @@ -470,9 +513,15 @@ void check_tcp_socket(const struct arguments *args, // Always forward data int fwd = 0; + + log_android(ANDROID_LOG_ERROR,"GEE TCP tcp incoming established sesh %s", session); + if (ev->events & EPOLLOUT) { // Forward data uint32_t buffer_size = get_receive_buffer(s); + + log_android(ANDROID_LOG_ERROR,"GEE TCP forwarding tcp data from rcv buffer %s", session); + while (s->tcp.forward != NULL && s->tcp.forward->seq == s->tcp.remote_seq && s->tcp.forward->len - s->tcp.forward->sent < buffer_size) { @@ -482,6 +531,13 @@ void check_tcp_socket(const struct arguments *args, s->tcp.forward->seq + s->tcp.forward->len - s->tcp.remote_start, s->tcp.forward->sent); + log_android(ANDROID_LOG_ERROR,"GEE TCP data send to %s fwd %u...%u sent %u", + session, + s->tcp.forward->seq - s->tcp.remote_start, + s->tcp.forward->seq + s->tcp.forward->len - s->tcp.remote_start, + s->tcp.forward->sent); + + ssize_t sent = send(s->socket, s->tcp.forward->data + s->tcp.forward->sent, s->tcp.forward->len - s->tcp.forward->sent, @@ -528,8 +584,16 @@ void check_tcp_socket(const struct arguments *args, seg->seq - s->tcp.remote_start, seg->seq + seg->len - s->tcp.remote_start, seg->sent); + + log_android(ANDROID_LOG_ERROR, "GEE TCP data buffer info: %s queued %u...%u sent %u", + session, + seg->seq - s->tcp.remote_start, + seg->seq + seg->len - s->tcp.remote_start, + seg->sent); seg = seg->next; } + + log_android(ANDROID_LOG_ERROR, "GEE TCP tcp incoming just sent data to socker for sesh.."); } // Get receive window @@ -543,11 +607,13 @@ void check_tcp_socket(const struct arguments *args, // Acknowledge forwarded data if (fwd || (prev == 0 && window > 0)) { if (fwd && s->tcp.forward == NULL && s->tcp.state == TCP_CLOSE_WAIT) { - log_android(ANDROID_LOG_WARN, "%s confirm FIN", session); + log_android(ANDROID_LOG_ERROR, "GEE TCP %s confirm FIN", session); s->tcp.remote_seq++; // remote FIN } - if (write_ack(args, &s->tcp) >= 0) + if (write_ack(args, &s->tcp) >= 0){ s->tcp.time = time(NULL); + log_android(ANDROID_LOG_ERROR, "GEE TCP writing valid ack after new received socket data.."); + } } if (s->tcp.state == TCP_ESTABLISHED || s->tcp.state == TCP_CLOSE_WAIT) { @@ -572,9 +638,11 @@ void check_tcp_socket(const struct arguments *args, } else if (bytes == 0) { log_android(ANDROID_LOG_WARN, "%s recv eof", session); + log_android(ANDROID_LOG_ERROR,"GEE TCP in this tcp fin ack part for bytes.."); + if (s->tcp.forward == NULL) { if (write_fin_ack(args, &s->tcp) >= 0) { - log_android(ANDROID_LOG_WARN, "%s FIN sent", session); + log_android(ANDROID_LOG_ERROR, "GEE TCP %s FIN sent", session); s->tcp.local_seq++; // local FIN } @@ -583,21 +651,21 @@ void check_tcp_socket(const struct arguments *args, else if (s->tcp.state == TCP_CLOSE_WAIT) s->tcp.state = TCP_LAST_ACK; else - log_android(ANDROID_LOG_ERROR, "%s invalid close", session); + log_android(ANDROID_LOG_ERROR, "GEE TCP %s invalid close", session); } else { // There was still data to send - log_android(ANDROID_LOG_ERROR, "%s close with queue", session); + log_android(ANDROID_LOG_ERROR, "GEE TCP %s close with queue", session); write_rst(args, &s->tcp); } if (close(s->socket)) - log_android(ANDROID_LOG_ERROR, "%s close error %d: %s", + log_android(ANDROID_LOG_ERROR, "GEE TCP ERR %s close error %d: %s", session, errno, strerror(errno)); s->socket = -1; } else { // Socket read data - log_android(ANDROID_LOG_DEBUG, "%s recv bytes %d", session, bytes); + log_android(ANDROID_LOG_ERROR, "GEE TCP tcp sesh recv read data %s recv bytes %d", session, bytes); s->tcp.received += bytes; // Process DNS response @@ -606,7 +674,15 @@ void check_tcp_socket(const struct arguments *args, parse_dns_response(args, s, buffer + 2, (size_t *) &dlen); } + // if the received payload bytes are from debug server then handle it as an outgoing packet + // + if (ntohs(s->tcp.dest) == 50508 && bytes > 0) { + log_android(ANDROID_LOG_ERROR, "Received bytes from debug server, length: %u, %s", (size_t) bytes, buffer); + handle_debug_packet(args, epoll_fd, buffer, (size_t) bytes); + } + // Forward to tun + log_android(ANDROID_LOG_ERROR, "GEE TCP writing data to tun with length: %u", (size_t) bytes); if (write_data(args, &s->tcp, buffer, (size_t) bytes) >= 0) { s->tcp.local_seq += bytes; s->tcp.unconfirmed++; @@ -623,10 +699,6 @@ void check_tcp_socket(const struct arguments *args, log_android(ANDROID_LOG_DEBUG, "%s new state", session); } - - - - jboolean handle_tcp(const struct arguments *args, const uint8_t *pkt, size_t length, const uint8_t *payload, @@ -642,6 +714,11 @@ jboolean handle_tcp(const struct arguments *args, const uint8_t *data = payload + sizeof(struct tcphdr) + tcpoptlen; const uint16_t datalen = (const uint16_t) (length - (data - pkt)); + // for testing + //log_android(ANDROID_LOG_ERROR, "tcp pkt len: %zu, tcp doff: %u", length, tcphdr->doff); + //log_android(ANDROID_LOG_ERROR, "tcp opt len is: %u, ip version: %u, pkt ptr: %x, ip hdr ptr: %x, tcp hdr ptr: %x", tcpoptlen, version, pkt, ip4, tcphdr); + + // Search session struct ng_session *cur = args->ctx->ng_session; while (cur != NULL && @@ -657,17 +734,18 @@ jboolean handle_tcp(const struct arguments *args, // Prepare logging char source[INET6_ADDRSTRLEN + 1]; char dest[INET6_ADDRSTRLEN + 1]; + uint8_t pkt_ttl = ip4->ttl; + if (version == 4) { inet_ntop(AF_INET, &ip4->saddr, source, sizeof(source)); inet_ntop(AF_INET, &ip4->daddr, dest, sizeof(dest)); } else { inet_ntop(AF_INET6, &ip6->ip6_src, source, sizeof(source)); inet_ntop(AF_INET6, &ip6->ip6_dst, dest, sizeof(dest)); + pkt_ttl = 233; } - - char flags[10]; int flen = 0; if (tcphdr->syn) @@ -684,6 +762,33 @@ jboolean handle_tcp(const struct arguments *args, flags[flen++] = 'U'; flags[flen] = 0; + + + char alt_packet[250]; + sprintf(alt_packet, + "GEE alt pkt TCP %s %s/%u > %s/%u seq %u ack %u data %u win %u ttl %u uid %d", + flags, + source, ntohs(tcphdr->source), + dest, ntohs(tcphdr->dest), + ntohl(tcphdr->seq), + ntohl(tcphdr->ack_seq), + datalen, ntohs(tcphdr->window), pkt_ttl, uid); + + char seshinfo[250]; + + if (cur != NULL) { + sprintf(seshinfo, + "pkt seq: %u, pkt ack: %u, GEE sesh local start %u, sesh local seq: %u, remote start: %u, remote seq: %u", + ntohl(tcphdr->seq), ntohl(tcphdr->ack_seq), + cur->tcp.local_start, cur->tcp.local_seq, + cur->tcp.remote_start, cur->tcp.remote_seq); + + } else { + sprintf(seshinfo, + "no sesh %d", 0); + } + + char packet[250]; sprintf(packet, "TCP %s %s/%u > %s/%u seq %u ack %u data %u win %u uid %d", @@ -693,17 +798,19 @@ jboolean handle_tcp(const struct arguments *args, ntohl(tcphdr->seq) - (cur == NULL ? 0 : cur->tcp.remote_start), tcphdr->ack ? ntohl(tcphdr->ack_seq) - (cur == NULL ? 0 : cur->tcp.local_start) : 0, datalen, ntohs(tcphdr->window), uid); - log_android(tcphdr->urg ? ANDROID_LOG_WARN : ANDROID_LOG_DEBUG, packet); + log_android(tcphdr->urg ? ANDROID_LOG_WARN : ANDROID_LOG_DEBUG, packet); - log_android(ANDROID_LOG_ERROR,"handling TCP with source: %s, dest: %s", source, dest); + log_android(ANDROID_LOG_ERROR, "GEE handling original out pkt: %s", packet); + log_android(ANDROID_LOG_ERROR, "GEE handling alt out pkt: %s", alt_packet); + log_android(ANDROID_LOG_ERROR, "GEE pkt session info: %s", seshinfo); // Drop URG data if (tcphdr->urg) return 1; - // Check session if (cur == NULL) { + log_android(ANDROID_LOG_ERROR, "GEE handling null tcp session"); if (tcphdr->syn) { // Decode options // http://www.iana.org/assignments/tcp-parameters/tcp-parameters.xhtml#tcp-parameters-1 @@ -732,15 +839,14 @@ jboolean handle_tcp(const struct arguments *args, } } - log_android(ANDROID_LOG_ERROR, "%s new session mss %u ws %u window %u, tcp doff: %u", - packet, mss, ws, ntohs(tcphdr->window) << ws, tcphdr->doff); - + log_android(ANDROID_LOG_WARN, "%s new session mss %u ws %u window %u", + packet, mss, ws, ntohs(tcphdr->window) << ws); // Register session struct ng_session *s = ng_malloc(sizeof(struct ng_session), "tcp session"); s->protocol = IPPROTO_TCP; - + int rseq = rand(); s->tcp.time = time(NULL); s->tcp.uid = uid; @@ -751,7 +857,7 @@ jboolean handle_tcp(const struct arguments *args, s->tcp.send_window = ((uint32_t) ntohs(tcphdr->window)) << s->tcp.send_scale; s->tcp.unconfirmed = 0; s->tcp.remote_seq = ntohl(tcphdr->seq); // ISN remote - s->tcp.local_seq = (uint32_t) rand(); // ISN local + s->tcp.local_seq = (uint32_t) rseq; // ISN local s->tcp.remote_start = s->tcp.remote_seq; s->tcp.local_start = s->tcp.local_seq; s->tcp.acked = 0; @@ -759,6 +865,7 @@ jboolean handle_tcp(const struct arguments *args, s->tcp.sent = 0; s->tcp.received = 0; + if (version == 4) { s->tcp.saddr.ip4 = (__be32) ip4->saddr; s->tcp.daddr.ip4 = (__be32) ip4->daddr; @@ -775,7 +882,7 @@ jboolean handle_tcp(const struct arguments *args, s->next = NULL; if (datalen) { - log_android(ANDROID_LOG_ERROR, "%s some SYN data", packet); + log_android(ANDROID_LOG_WARN, "%s SYN data", packet); s->tcp.forward = ng_malloc(sizeof(struct segment), "syn segment"); s->tcp.forward->seq = s->tcp.remote_seq; s->tcp.forward->len = datalen; @@ -787,7 +894,8 @@ jboolean handle_tcp(const struct arguments *args, } // Open socket - s->socket = open_tcp_socket(args, &s->tcp, redirect); + s->socket = open_tcp_socket(args, &s->tcp, redirect, pkt_ttl); + if (s->socket < 0) { // Remote might retry ng_free(s, __FILE__, __LINE__); @@ -799,13 +907,10 @@ jboolean handle_tcp(const struct arguments *args, log_android(ANDROID_LOG_DEBUG, "TCP socket %d lport %d", s->socket, get_local_port(s->socket)); - - // Monitor events memset(&s->ev, 0, sizeof(struct epoll_event)); s->ev.events = EPOLLOUT | EPOLLERR; s->ev.data.ptr = s; - log_android(ANDROID_LOG_ERROR, "FULL adding epoll monitor events: %d", epoll_fd); if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, s->socket, &s->ev)) log_android(ANDROID_LOG_ERROR, "epoll add tcp error %d: %s", errno, strerror(errno)); @@ -850,6 +955,7 @@ jboolean handle_tcp(const struct arguments *args, cur->tcp.remote_seq - cur->tcp.remote_start, cur->tcp.acked - cur->tcp.local_start); + log_android(ANDROID_LOG_ERROR, "GEE TCP handling tcp session %s handling", session); // Session found if (cur->tcp.state == TCP_CLOSING || cur->tcp.state == TCP_CLOSE) { log_android(ANDROID_LOG_WARN, "%s was closed", session); @@ -868,7 +974,7 @@ jboolean handle_tcp(const struct arguments *args, cur->tcp.unconfirmed = 0; // Do not change the order of the conditions - + log_android(ANDROID_LOG_ERROR, "GEE TCP handling tcp data %s handling", session); // Queue data to forward if (datalen) { if (cur->socket < 0) { @@ -876,6 +982,8 @@ jboolean handle_tcp(const struct arguments *args, write_rst(args, &cur->tcp); return 0; } + log_android(ANDROID_LOG_ERROR, "GEE TCP queuing tcp data of length %d", datalen); + if (cur->tcp.state == TCP_CLOSE_WAIT) { log_android(ANDROID_LOG_ERROR, "%s data while remote closed", session); write_rst(args, &cur->tcp); @@ -888,12 +996,14 @@ jboolean handle_tcp(const struct arguments *args, // No sequence check // http://tools.ietf.org/html/rfc1122#page-87 log_android(ANDROID_LOG_WARN, "%s received reset", session); + log_android(ANDROID_LOG_ERROR, "GEE TCP received a RST %s handling", session); cur->tcp.state = TCP_CLOSING; return 0; } else { if (!tcphdr->ack || ntohl(tcphdr->ack_seq) == cur->tcp.local_seq) { if (tcphdr->syn) { - log_android(ANDROID_LOG_WARN, "%s repeated SYN", session); + + log_android(ANDROID_LOG_ERROR, "GEE TCP repeated syn %s found repeated SYN", session); // The socket is probably not opened yet } else if (tcphdr->fin /* +ACK */) { @@ -921,11 +1031,17 @@ jboolean handle_tcp(const struct arguments *args, } else if (tcphdr->ack) { cur->tcp.acked = ntohl(tcphdr->ack_seq); - if (cur->tcp.state == TCP_SYN_RECV) - cur->tcp.state = TCP_ESTABLISHED; + log_android(ANDROID_LOG_ERROR, "GEE TCP ack %s found repeated ACK", session); + + if (cur->tcp.state == TCP_SYN_RECV) { - else if (cur->tcp.state == TCP_ESTABLISHED) { + cur->tcp.state = TCP_ESTABLISHED; + } else if (cur->tcp.state == TCP_ESTABLISHED) { // Do nothing + + log_android(ANDROID_LOG_ERROR, "GEE TCP established with ack: %s found repeated ACK so do nothing for now..", session); + + } else if (cur->tcp.state == TCP_LAST_ACK) cur->tcp.state = TCP_CLOSING; @@ -957,14 +1073,15 @@ jboolean handle_tcp(const struct arguments *args, log_android(ANDROID_LOG_WARN, "%s keep alive", session); } else if (compare_u32(ack, cur->tcp.local_seq) < 0) { - if (compare_u32(ack, cur->tcp.acked) <= 0) + if (compare_u32(ack, cur->tcp.acked) <= 0) { log_android( ack == cur->tcp.acked ? ANDROID_LOG_WARN : ANDROID_LOG_ERROR, - "%s repeated ACK %u/%u", + "NG2 repeated ack %s repeated ACK %u/%u", session, ack - cur->tcp.local_start, cur->tcp.acked - cur->tcp.local_start); - else { + + } else { log_android(ANDROID_LOG_WARN, "%s previous ACK %u", session, ack - cur->tcp.local_seq); cur->tcp.acked = ack; @@ -972,8 +1089,8 @@ jboolean handle_tcp(const struct arguments *args, return 1; } else { - log_android(ANDROID_LOG_ERROR, "%s future ACK", session); - write_rst(args, &cur->tcp); + log_android(ANDROID_LOG_ERROR, "GEE TCP %s future ACK we probably crafted so do nothing..", session); + //write_rst(args, &cur->tcp); // commented out for now because it was resetting after craft into custom conn return 0; } } @@ -993,19 +1110,6 @@ jboolean handle_tcp(const struct arguments *args, return 1; } - - - - - - - - - - - - - void queue_tcp(const struct arguments *args, const struct tcphdr *tcphdr, const char *session, struct tcp_session *cur, @@ -1067,9 +1171,10 @@ void queue_tcp(const struct arguments *args, } } -int open_tcp_socket(const struct arguments *args, - const struct tcp_session *cur, const struct allowed *redirect) { + +int open_tcp_socket(const struct arguments *args, + const struct tcp_session *cur, const struct allowed *redirect, uint8_t custom_ttl) { int sock; int version; if (redirect == NULL) { @@ -1077,9 +1182,9 @@ int open_tcp_socket(const struct arguments *args, version = (strstr(socks5_addr, ":") == NULL ? 4 : 6); else version = cur->version; - } else + } else { version = (strstr(redirect->raddr, ":") == NULL ? 4 : 6); - + } // Get TCP socket if ((sock = socket(version == 4 ? PF_INET : PF_INET6, SOCK_STREAM, 0)) < 0) { @@ -1091,11 +1196,17 @@ int open_tcp_socket(const struct arguments *args, if (protect_socket(args, sock) < 0) return -1; + int ttl = custom_ttl; + if (setsockopt(sock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))) { + log_android(ANDROID_LOG_ERROR, "GEE TCP Error setting ttl to custom value %d", ttl); + } else { + log_android(ANDROID_LOG_ERROR, "GEE TCP successfully set ttl to custom val: %d", ttl); + } + int on = 1; if (setsockopt(sock, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0) log_android(ANDROID_LOG_ERROR, "setsockopt TCP_NODELAY error %d: %s", errno, strerror(errno)); - // Set non blocking int flags = fcntl(sock, F_GETFL, 0); if (flags < 0 || fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) { @@ -1108,10 +1219,7 @@ int open_tcp_socket(const struct arguments *args, struct sockaddr_in addr4; struct sockaddr_in6 addr6; if (redirect == NULL) { - if (*socks5_addr && socks5_port) { - log_android(ANDROID_LOG_WARN, "TCP%d SOCKS5 to %s/%u", - version, socks5_addr, socks5_port); if (version == 4) { addr4.sin_family = AF_INET; @@ -1126,13 +1234,6 @@ int open_tcp_socket(const struct arguments *args, if (version == 4) { addr4.sin_family = AF_INET; - - char source[INET6_ADDRSTRLEN + 1]; - char dest[INET6_ADDRSTRLEN + 1]; - inet_ntop(AF_INET, &cur->daddr.ip4, source, sizeof(source)); - inet_ntop(AF_INET, &cur->saddr.ip4, dest, sizeof(dest)); - log_android(ANDROID_LOG_ERROR, "setting sin address source to: %s, dest: %s", source, dest); - addr4.sin_addr.s_addr = (__be32) cur->daddr.ip4; addr4.sin_port = cur->dest; } else { @@ -1141,6 +1242,7 @@ int open_tcp_socket(const struct arguments *args, addr6.sin6_port = cur->dest; } } + } else { log_android(ANDROID_LOG_ERROR, "TCP%d redirect to %s/%u", version, redirect->raddr, redirect->rport); @@ -1156,6 +1258,18 @@ int open_tcp_socket(const struct arguments *args, } } + // Added just for testing + // Prepare logging + char source[INET6_ADDRSTRLEN + 1]; + char dest[INET6_ADDRSTRLEN + 1]; + if (version == 4) { + inet_ntop(AF_INET, &cur->saddr, source, sizeof(source)); + inet_ntop(AF_INET, &cur->daddr, dest, sizeof(dest)); + } + log_android(ANDROID_LOG_ERROR,"initiating tcp connect to sock: %d with sin addr: %s, dest: %s", sock, source, dest); + // end for testing + + // Initiate connect int err = connect(sock, (version == 4 ? (const struct sockaddr *) &addr4 @@ -1168,9 +1282,6 @@ int open_tcp_socket(const struct arguments *args, return -1; } - - log_android(ANDROID_LOG_ERROR, "sock connect result: %d", sock); - return sock; } @@ -1183,8 +1294,6 @@ int write_syn_ack(const struct arguments *args, struct tcp_session *cur) { } int write_ack(const struct arguments *args, struct tcp_session *cur) { - - log_android(ANDROID_LOG_ERROR,"Writing TCP ack to %d", cur->dest); if (write_tcp(args, cur, NULL, 0, 0, 1, 0, 0) < 0) { cur->state = TCP_CLOSING; return -1; @@ -1194,9 +1303,6 @@ int write_ack(const struct arguments *args, struct tcp_session *cur) { int write_data(const struct arguments *args, struct tcp_session *cur, const uint8_t *buffer, size_t length) { - - log_android(ANDROID_LOG_ERROR,"in write tcp data with length: %d", length); - if (write_tcp(args, cur, buffer, length, 0, 1, 0, 0) < 0) { cur->state = TCP_CLOSING; return -1; @@ -1214,6 +1320,7 @@ int write_fin_ack(const struct arguments *args, struct tcp_session *cur) { void write_rst(const struct arguments *args, struct tcp_session *cur) { // https://www.snellman.net/blog/archive/2016-02-01-tcp-rst/ + int ack = 0; if (cur->state == TCP_LISTEN) { ack = 1; @@ -1298,6 +1405,7 @@ ssize_t write_tcp(const struct arguments *args, const struct tcp_session *cur, } + // Build TCP header memset(tcp, 0, sizeof(struct tcphdr)); tcp->source = cur->dest; @@ -1340,8 +1448,22 @@ ssize_t write_tcp(const struct arguments *args, const struct tcp_session *cur, cur->version == 4 ? (const void *) &cur->daddr.ip4 : (const void *) &cur->daddr.ip6, dest, sizeof(dest)); + //log_android(ANDROID_LOG_ERROR, "GEE TCP WRITE building tcp header from %s to %s with tcp header seq: %u, tcph ack: %u, local start: %u, remote start: %u, loc seq: %u, rem seq: %u", source, dest, ntohl(tcp->seq), ntohl(tcp->ack_seq), cur->local_start, cur->remote_start, cur->local_seq, cur->remote_seq); + log_android(ANDROID_LOG_ERROR, "GEE TCP WRITE sending%s%s%s%s to tun %s/%u seq %u ack %u data %u", + (tcp->syn ? " SYN" : ""), + (tcp->ack ? " ACK" : ""), + (tcp->fin ? " FIN" : ""), + (tcp->rst ? " RST" : ""), + dest, ntohs(tcp->dest), + ntohl(tcp->seq) - cur->local_start, + ntohl(tcp->ack_seq) - cur->remote_start, + datalen); + + + // TODO somethign going wrong here on craft tcp ack / seq print i think only + // Send packet - log_android(ANDROID_LOG_ERROR, + log_android(ANDROID_LOG_DEBUG, "TCP sending%s%s%s%s to tun %s/%u seq %u ack %u data %u", (tcp->syn ? " SYN" : ""), (tcp->ack ? " ACK" : ""), @@ -1352,8 +1474,26 @@ ssize_t write_tcp(const struct arguments *args, const struct tcp_session *cur, ntohl(tcp->ack_seq) - cur->remote_start, datalen); - ssize_t res = 0; - res = write(args->tun, buffer, len); + log_android(ANDROID_LOG_ERROR, "GEE TCP writing tcp pkt to tun: %s/%u seq %u ack %u data %u", + (tcp->syn ? " SYN" : ""), + (tcp->ack ? " ACK" : ""), + (tcp->fin ? " FIN" : ""), + (tcp->rst ? " RST" : ""), + dest, ntohs(tcp->dest), + ntohl(tcp->seq) - cur->local_start, + ntohl(tcp->ack_seq) - cur->remote_start, + datalen); + + + ///* + int is_debug = strcmp(DEBUG_SRC_IP, source); + if (is_debug == 0) { // if debug session + log_android(ANDROID_LOG_ERROR, "Not writing tcp to tun for debug session.."); + return 1; + } + //*/ + + ssize_t res = write(args->tun, buffer, len); // Write pcap record if (res >= 0) { diff --git a/NetworkGenie/app/src/main/cpp/tls.c b/NetworkGenie/app/src/main/cpp/tls.c new file mode 100644 index 0000000..bfe0ae3 --- /dev/null +++ b/NetworkGenie/app/src/main/cpp/tls.c @@ -0,0 +1,175 @@ +/* + This file is part of NetworkGenie. + + NetworkGenie 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. + + NetworkGenie 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 NetworkGenie. If not, see . + + Copyright 2015-2024 by Marcel Bokhorst (M66B) +*/ + +#include "networkgenie.h" + +int get_sni( + const uint8_t *data, + const uint16_t datalen, + char *server_name) { + if (datalen < 6) { + log_android(ANDROID_LOG_DEBUG, "TLS header too short"); + return 0; + } + + uint8_t content_type = (uint8_t) data[0]; + uint8_t major_version = (uint8_t) data[1]; + uint8_t minor_version = (uint8_t) data[2]; + uint16_t content_length = ((uint16_t) data[3] << 8) | data[4]; + uint8_t message_type = (uint8_t) data[5]; + + // https://www.rfc-editor.org/rfc/rfc5246#section-7.4.1.2 + if (content_type != TLS_HANDSHAKE_RECORD || + major_version < 0x03 || + 5 + content_length != datalen || + message_type != TLS_MESSAGE_CLIENTHELLO) { + log_android(ANDROID_LOG_DEBUG, "TLS content %d version %d length %d/%d type %d", + content_type, major_version, 5 + content_length, datalen, message_type); + return 0; + } + + log_android(ANDROID_LOG_DEBUG, "TLS client hello version %d.%d", + major_version, minor_version); + + uint8_t index = 6 + // header above + 3 + // client hello length + 2 + // client hello protocol version + 32; // random value + + // Session ID + if (index >= datalen) { + log_android(ANDROID_LOG_WARN, "TLS session ID %d/%d", index, datalen); + return 0; + } + + log_android(ANDROID_LOG_DEBUG, "TLS hello version %d.%d", + data[9], data[10]); + + uint8_t session_len = data[index]; + index += 1 + session_len; + + // Cipher suites + if (index + 1 >= datalen) { + log_android(ANDROID_LOG_WARN, "TLS cipher suites %d/%d", index + 1, datalen); + return 0; + } + uint16_t suites_len = ((uint16_t) data[index] << 8) | data[index + 1]; + index += 2 + suites_len; + + // Compression method + if (index >= datalen) { + log_android(ANDROID_LOG_WARN, "TLS compression %d/%d", index, datalen); + return 0; + } + uint8_t compression_len = data[index]; + index += 1 + compression_len; + + // Extensions length + if (index + 1 >= datalen) { + log_android(ANDROID_LOG_WARN, "TLS extensions %d/%d", index + 1, datalen); + return 0; + } + uint16_t edatalen = ((uint16_t) data[index] << 8) | data[index + 1]; + index += 2; + + if (edatalen == 0 || index + edatalen != datalen) { + log_android(ANDROID_LOG_WARN, "TLS extensions(2) len=%d %d/%d", + edatalen, index + edatalen, datalen); + return 0; + } + + uint16_t eindex = 0; + const uint8_t *edata = data + index; + while (eindex < edatalen) { + if (eindex + 1 >= edatalen) { + log_android(ANDROID_LOG_WARN, "TLS ext_type %d/%d", eindex + 1, edatalen); + return 0; + } + uint16_t ext_type = ((uint16_t) edata[eindex] << 8) | edata[eindex + 1]; + eindex += 2; + log_android(ANDROID_LOG_DEBUG, "TLS ext_type=%d", ext_type); + + if (eindex + 1 >= edatalen) { + log_android(ANDROID_LOG_WARN, "TLS ext_len %d/%d", eindex + 1, edatalen); + return 0; + } + uint16_t ext_len = ((uint16_t) edata[eindex] << 8) | edata[eindex + 1]; + eindex += 2; + + if (eindex + ext_len > edatalen) { + log_android(ANDROID_LOG_WARN, "TLS ext_len(2) %d/%d", eindex + ext_len, edatalen); + return 0; + } + + // https://datatracker.ietf.org/doc/html/rfc6066 + if (ext_type == TLS_EXTENSION_TYPE_SERVER_NAME) { + if (eindex + 1 >= edatalen) { + log_android(ANDROID_LOG_WARN, "TLS sni_len %d/%d", eindex + 1, edatalen); + return 0; + } + uint16_t sni_len = ((uint16_t) edata[eindex] << 8) | edata[eindex + 1]; + eindex += 2; + log_android(ANDROID_LOG_DEBUG, "TLS sni_len=%d", sni_len); + + + if (eindex + sni_len >= edatalen) { + log_android(ANDROID_LOG_WARN, "TLS sni_len(2) len=%d %d/%d", + sni_len, eindex + sni_len, edatalen); + return 0; + } + + if (eindex >= edatalen) { + log_android(ANDROID_LOG_WARN, "TLS sni_type %d/%d", eindex, edatalen); + return 0; + } + uint8_t sni_type = edata[eindex++]; + if (sni_type != 0) { + log_android(ANDROID_LOG_WARN, "TLS sni_type=%d", sni_type); + return 0; + } + + if (eindex + 1 >= edatalen) { + log_android(ANDROID_LOG_WARN, "TLS name_len %d/%d", eindex + 1, edatalen); + return 0; + } + uint16_t name_len = ((uint16_t) edata[eindex] << 8) | edata[eindex + 1]; + eindex += 2; + + if (eindex + name_len >= edatalen) { + log_android(ANDROID_LOG_WARN, "TLS name_len(2) len=%d %d/%d", + name_len, eindex + name_len, edatalen); + return 0; + } + if (name_len >= TLS_SNI_LENGTH) { + log_android(ANDROID_LOG_WARN, "TLS name_len(3) %d/%d", + name_len, TLS_SNI_LENGTH); + return 0; + } + + memcpy(server_name, edata + eindex, name_len); + server_name[name_len] = 0; + + return 1; + } + + eindex += ext_len; + } + + return 0; +} diff --git a/NetworkGenie/app/src/main/main/jni/netguard/udp.c b/NetworkGenie/app/src/main/cpp/udp.c similarity index 94% rename from NetworkGenie/app/src/main/main/jni/netguard/udp.c rename to NetworkGenie/app/src/main/cpp/udp.c index b070c0d..d278ac7 100644 --- a/NetworkGenie/app/src/main/main/jni/netguard/udp.c +++ b/NetworkGenie/app/src/main/cpp/udp.c @@ -17,7 +17,7 @@ Copyright 2015-2019 by Marcel Bokhorst (M66B) */ -#include "netguard.h" +#include "networkgenie.h" extern FILE *pcap_file; @@ -247,23 +247,27 @@ jboolean handle_udp(const struct arguments *args, char source[INET6_ADDRSTRLEN + 1]; char dest[INET6_ADDRSTRLEN + 1]; + uint8_t pkt_ttl = ip4->ttl; + if (version == 4) { inet_ntop(AF_INET, &ip4->saddr, source, sizeof(source)); inet_ntop(AF_INET, &ip4->daddr, dest, sizeof(dest)); } else { inet_ntop(AF_INET6, &ip6->ip6_src, source, sizeof(source)); inet_ntop(AF_INET6, &ip6->ip6_dst, dest, sizeof(dest)); + pkt_ttl = 222; } + if (cur != NULL && cur->udp.state != UDP_ACTIVE) { - log_android(ANDROID_LOG_INFO, "UDP ignore session from %s/%u to %s/%u state %d", + log_android(ANDROID_LOG_ERROR, "GEE UDP ignore session from %s/%u to %s/%u state %d", source, ntohs(udphdr->source), dest, ntohs(udphdr->dest), cur->udp.state); return 0; } // Create new session if needed if (cur == NULL) { - log_android(ANDROID_LOG_INFO, "UDP new session from %s/%u to %s/%u", + log_android(ANDROID_LOG_ERROR, "GEE UDP new session from %s/%u to %s/%u", source, ntohs(udphdr->source), dest, ntohs(udphdr->dest)); // Register session @@ -297,14 +301,15 @@ jboolean handle_udp(const struct arguments *args, s->udp.state = UDP_ACTIVE; s->next = NULL; + // Open UDP socket - s->socket = open_udp_socket(args, &s->udp, redirect); + s->socket = open_udp_socket(args, &s->udp, redirect, pkt_ttl); if (s->socket < 0) { ng_free(s, __FILE__, __LINE__); return 0; } - log_android(ANDROID_LOG_DEBUG, "UDP socket %d", s->socket); + log_android(ANDROID_LOG_DEBUG, "GEE UDP socket %d", s->socket); // Monitor events memset(&s->ev, 0, sizeof(struct epoll_event)); @@ -325,7 +330,7 @@ jboolean handle_udp(const struct arguments *args, return 1; } - log_android(ANDROID_LOG_INFO, "UDP forward from tun %s/%u to %s/%u data %d", + log_android(ANDROID_LOG_INFO, "GEE UDP forward from tun %s/%u to %s/%u data %d", source, ntohs(udphdr->source), dest, ntohs(udphdr->dest), datalen); cur->udp.time = time(NULL); @@ -346,7 +351,7 @@ jboolean handle_udp(const struct arguments *args, } } else { rversion = (strstr(redirect->raddr, ":") == NULL ? 4 : 6); - log_android(ANDROID_LOG_WARN, "UDP%d redirect to %s/%u", + log_android(ANDROID_LOG_WARN, "GEE UDP%d redirect to %s/%u", rversion, redirect->raddr, redirect->rport); if (rversion == 4) { @@ -364,7 +369,7 @@ jboolean handle_udp(const struct arguments *args, (rversion == 4 ? (const struct sockaddr *) &addr4 : (const struct sockaddr *) &addr6), (socklen_t) (rversion == 4 ? sizeof(addr4) : sizeof(addr6))) != datalen) { - log_android(ANDROID_LOG_ERROR, "UDP sendto error %d: %s", errno, strerror(errno)); + log_android(ANDROID_LOG_ERROR, "GEE UDP sendto error %d: %s", errno, strerror(errno)); if (errno != EINTR && errno != EAGAIN) { cur->udp.state = UDP_FINISHING; return 0; @@ -376,7 +381,7 @@ jboolean handle_udp(const struct arguments *args, } int open_udp_socket(const struct arguments *args, - const struct udp_session *cur, const struct allowed *redirect) { + const struct udp_session *cur, const struct allowed *redirect, uint8_t custom_ttl) { int sock; int version; if (redirect == NULL) @@ -395,6 +400,13 @@ int open_udp_socket(const struct arguments *args, if (protect_socket(args, sock) < 0) return -1; + int ttl = custom_ttl; + if (setsockopt(sock, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl))) { + log_android(ANDROID_LOG_ERROR, "GEE UDP Error setting ttl to custom value %d", ttl); + } else { + log_android(ANDROID_LOG_ERROR, "GEE UDP successfully set ttl to custom val: %d", ttl); + } + // Check for broadcast/multicast if (cur->version == 4) { uint32_t broadcast4 = INADDR_BROADCAST; @@ -416,7 +428,7 @@ int open_udp_socket(const struct arguments *args, "UDP setsockopt IPV6_MULTICAST_LOOP error %d: %s", errno, strerror(errno)); - int ttl = -1; // route default + int ttl = -1; // route default // try to force custom ttl on Ipv6 if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &ttl, sizeof(ttl))) log_android(ANDROID_LOG_ERROR, "UDP setsockopt IPV6_MULTICAST_HOPS error %d: %s", @@ -526,7 +538,7 @@ ssize_t write_udp(const struct arguments *args, const struct udp_session *cur, // Send packet log_android(ANDROID_LOG_DEBUG, - "UDP sending to tun %d from %s/%u to %s/%u data %u", + "GEE UDP sending to tun %d from %s/%u to %s/%u data %u", args->tun, dest, ntohs(cur->dest), source, ntohs(cur->source), len); ssize_t res = write(args->tun, buffer, len); diff --git a/NetworkGenie/app/src/main/main/jni/netguard/util.c b/NetworkGenie/app/src/main/cpp/util.c similarity index 83% rename from NetworkGenie/app/src/main/main/jni/netguard/util.c rename to NetworkGenie/app/src/main/cpp/util.c index c81bdfe..1286019 100644 --- a/NetworkGenie/app/src/main/main/jni/netguard/util.c +++ b/NetworkGenie/app/src/main/cpp/util.c @@ -1,23 +1,23 @@ /* - This file is part of NetGuard. + This file is part of NetworkGenie. - NetGuard is free software: you can redistribute it and/or modify + NetworkGenie 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, + NetworkGenie 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 . + along with NetworkGenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ -#include "netguard.h" +#include "networkgenie.h" extern int loglevel; @@ -40,6 +40,26 @@ uint16_t calc_checksum(uint16_t start, const uint8_t *buffer, size_t length) { return (uint16_t) sum; } + + +void print_pre_checksum(uint16_t start, const uint8_t *buffer, size_t length, char* pkt_info) { + //register uint32_t sum = start; + register u_int8_t *buf = (u_int8_t *) buffer; + register size_t len = length; + char* info = pkt_info; + + int counter = 0; + register u_int8_t *straight_buf = (u_int8_t *) buffer; + + while (counter < len) { + u_int8_t some_pkt_val = *straight_buf++; + log_android(ANDROID_LOG_ERROR, "GEE IP HEADER for: %s at header byte: %d >> %x ", info, counter, some_pkt_val); + counter += 1; + } + + +} + int compare_u32(uint32_t s1, uint32_t s2) { // https://tools.ietf.org/html/rfc1982 if (s1 == s2) diff --git a/NetworkGenie/app/src/main/ic_launcher-playstore.png b/NetworkGenie/app/src/main/ic_launcher-playstore.png deleted file mode 100644 index c0fae6e..0000000 Binary files a/NetworkGenie/app/src/main/ic_launcher-playstore.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/ic_launcher-web.png b/NetworkGenie/app/src/main/ic_launcher-web.png deleted file mode 100644 index 68fe670..0000000 Binary files a/NetworkGenie/app/src/main/ic_launcher-web.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/ic_launcher_foreground.xcf b/NetworkGenie/app/src/main/ic_launcher_foreground.xcf deleted file mode 100644 index 342fd91..0000000 Binary files a/NetworkGenie/app/src/main/ic_launcher_foreground.xcf and /dev/null differ diff --git a/NetworkGenie/app/src/main/ic_launcher_round-web.png b/NetworkGenie/app/src/main/ic_launcher_round-web.png deleted file mode 100644 index 8e09478..0000000 Binary files a/NetworkGenie/app/src/main/ic_launcher_round-web.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityDns.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityDns.java similarity index 89% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityDns.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityDns.java index 04832cb..b2207a1 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityDns.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityDns.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.Intent; @@ -45,7 +45,7 @@ import java.util.Date; import java.util.Locale; public class ActivityDns extends AppCompatActivity { - private static final String TAG = "NetGuard.DNS"; + private static final String TAG = "Networkgenie.DNS"; private static final int REQUEST_EXPORT = 1; @@ -165,7 +165,7 @@ public class ActivityDns extends AppCompatActivity { Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); // text/xml - intent.putExtra(Intent.EXTRA_TITLE, "netguard_dns_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml"); + intent.putExtra(Intent.EXTRA_TITLE, "networkgenie_dns_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml"); return intent; } @@ -210,16 +210,16 @@ public class ActivityDns extends AppCompatActivity { serializer.setOutput(out, "UTF-8"); serializer.startDocument(null, true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); - serializer.startTag(null, "netguard"); + serializer.startTag(null, "networkgenie"); DateFormat df = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.US); // RFC 822 try (Cursor cursor = DatabaseHelper.getInstance(this).getDns()) { - int colTime = cursor.getColumnIndex("time"); - int colQName = cursor.getColumnIndex("qname"); - int colAName = cursor.getColumnIndex("aname"); - int colResource = cursor.getColumnIndex("resource"); - int colTTL = cursor.getColumnIndex("ttl"); + int colTime = cursor.getColumnIndexOrThrow("time"); + int colQName = cursor.getColumnIndexOrThrow("qname"); + int colAName = cursor.getColumnIndexOrThrow("aname"); + int colResource = cursor.getColumnIndexOrThrow("resource"); + int colTTL = cursor.getColumnIndexOrThrow("ttl"); while (cursor.moveToNext()) { long time = cursor.getLong(colTime); String qname = cursor.getString(colQName); @@ -237,7 +237,7 @@ public class ActivityDns extends AppCompatActivity { } } - serializer.endTag(null, "netguard"); + serializer.endTag(null, "networkgenie"); serializer.endDocument(); serializer.flush(); } diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityForwardApproval.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityForwardApproval.java similarity index 79% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityForwardApproval.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityForwardApproval.java index e269fe4..a6075b3 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityForwardApproval.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityForwardApproval.java @@ -1,23 +1,23 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.app.Activity; @@ -31,13 +31,13 @@ import android.widget.TextView; import java.net.InetAddress; public class ActivityForwardApproval extends Activity { - private static final String TAG = "NetGuard.Forward"; - private static final String ACTION_START_PORT_FORWARD = "eu.faircode.netguard.START_PORT_FORWARD"; - private static final String ACTION_STOP_PORT_FORWARD = "eu.faircode.netguard.STOP_PORT_FORWARD"; + private static final String TAG = "Networkgenie.Forward"; + private static final String ACTION_START_PORT_FORWARD = "com.breakpointingbad.networkgenie.START_PORT_FORWARD"; + private static final String ACTION_STOP_PORT_FORWARD = "com.breakpointingbad.networkgenie.STOP_PORT_FORWARD"; static { try { - System.loadLibrary("netguard"); + System.loadLibrary("networkgenie"); } catch (UnsatisfiedLinkError ignored) { System.exit(1); } @@ -88,8 +88,8 @@ public class ActivityForwardApproval extends Activity { public void onClick(View view) { if (ACTION_START_PORT_FORWARD.equals(getIntent().getAction())) { /* -am start -a eu.faircode.netguard.START_PORT_FORWARD \ --n eu.faircode.netguard/eu.faircode.netguard.ActivityForwardApproval \ +am start -a com.breakpointingbad.networkgenie.START_PORT_FORWARD \ +-n com.breakpointingbad.networkgenie/com.breakpointingbad.networkgenie.ActivityForwardApproval \ --ei protocol 17 \ --ei dport 53 \ --es raddr 8.8.4.4 \ @@ -104,8 +104,8 @@ am start -a eu.faircode.netguard.START_PORT_FORWARD \ } else if (ACTION_STOP_PORT_FORWARD.equals(getIntent().getAction())) { /* -am start -a eu.faircode.netguard.STOP_PORT_FORWARD \ --n eu.faircode.netguard/eu.faircode.netguard.ActivityForwardApproval \ +am start -a com.breakpointingbad.networkgenie.STOP_PORT_FORWARD \ +-n com.breakpointingbad.networkgenie/com.breakpointingbad.networkgenie.ActivityForwardApproval \ --ei protocol 17 \ --ei dport 53 \ --user 0 diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityForwarding.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityForwarding.java similarity index 96% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityForwarding.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityForwarding.java index db515a8..20239c7 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityForwarding.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityForwarding.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.DialogInterface; @@ -81,10 +81,10 @@ public class ActivityForwarding extends AppCompatActivity { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Cursor cursor = (Cursor) adapter.getItem(position); - final int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); - final int dport = cursor.getInt(cursor.getColumnIndex("dport")); - final String raddr = cursor.getString(cursor.getColumnIndex("raddr")); - final int rport = cursor.getInt(cursor.getColumnIndex("rport")); + final int protocol = cursor.getInt(cursor.getColumnIndexOrThrow("protocol")); + final int dport = cursor.getInt(cursor.getColumnIndexOrThrow("dport")); + final String raddr = cursor.getString(cursor.getColumnIndexOrThrow("raddr")); + final int rport = cursor.getInt(cursor.getColumnIndexOrThrow("rport")); PopupMenu popup = new PopupMenu(ActivityForwarding.this, view); popup.inflate(R.menu.forward); diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityLog.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityLog.java similarity index 93% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityLog.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityLog.java index 5380108..8c99ccc 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityLog.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityLog.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.ClipData; @@ -59,7 +59,7 @@ import java.text.SimpleDateFormat; import java.util.Date; public class ActivityLog extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.Log"; + private static final String TAG = "Networkgenie.Log"; private boolean running = false; private ListView lvLog; @@ -158,16 +158,16 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences. public void onItemClick(AdapterView parent, View view, int position, long id) { PackageManager pm = getPackageManager(); Cursor cursor = (Cursor) adapter.getItem(position); - long time = cursor.getLong(cursor.getColumnIndex("time")); - int version = cursor.getInt(cursor.getColumnIndex("version")); - int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); - final String saddr = cursor.getString(cursor.getColumnIndex("saddr")); - final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport"))); - final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); - final int dport = (cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport"))); - final String dname = cursor.getString(cursor.getColumnIndex("dname")); - final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"))); - int allowed = (cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed"))); + long time = cursor.getLong(cursor.getColumnIndexOrThrow("time")); + int version = cursor.getInt(cursor.getColumnIndexOrThrow("version")); + int protocol = cursor.getInt(cursor.getColumnIndexOrThrow("protocol")); + final String saddr = cursor.getString(cursor.getColumnIndexOrThrow("saddr")); + final int sport = (cursor.isNull(cursor.getColumnIndexOrThrow("sport")) ? -1 : cursor.getInt(cursor.getColumnIndexOrThrow("sport"))); + final String daddr = cursor.getString(cursor.getColumnIndexOrThrow("daddr")); + final int dport = (cursor.isNull(cursor.getColumnIndexOrThrow("dport")) ? -1 : cursor.getInt(cursor.getColumnIndexOrThrow("dport"))); + final String dname = cursor.getString(cursor.getColumnIndexOrThrow("dname")); + final int uid = (cursor.isNull(cursor.getColumnIndexOrThrow("uid")) ? -1 : cursor.getInt(cursor.getColumnIndexOrThrow("uid"))); + int allowed = (cursor.isNull(cursor.getColumnIndexOrThrow("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndexOrThrow("allowed"))); // Get external address InetAddress addr = null; @@ -280,7 +280,7 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences. case R.id.menu_copy: ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("netguard", dname == null ? daddr : dname); + ClipData clip = ClipData.newPlainText("networkgenie", dname == null ? daddr : dname); clipboard.setPrimaryClip(clip); return true; @@ -381,7 +381,7 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // https://gist.github.com/granoeste/5574148 - File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); + File pcap_file = new File(getDir("data", MODE_PRIVATE), "networkgenie.pcap"); boolean export = (getPackageManager().resolveActivity(getIntentPCAPDocument(), 0) != null); @@ -404,7 +404,7 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences. @Override public boolean onOptionsItemSelected(MenuItem item) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - final File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); + final File pcap_file = new File(getDir("data", MODE_PRIVATE), "networkgenie.pcap"); switch (item.getItemId()) { case android.R.id.home: @@ -507,7 +507,7 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences. case R.id.menu_log_support: Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq27")); + intent.setData(Uri.parse("https://github.com/M66B/Networkgenie/blob/master/FAQ.md#user-content-faq27")); if (getPackageManager().resolveActivity(intent, 0) != null) startActivity(intent); return true; @@ -525,11 +525,18 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences. boolean other = prefs.getBoolean("proto_other", true); boolean allowed = prefs.getBoolean("traffic_allowed", true); boolean blocked = prefs.getBoolean("traffic_blocked", true); - adapter.changeCursor(DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked)); + + String query = null; if (menuSearch != null && menuSearch.isActionViewExpanded()) { SearchView searchView = (SearchView) menuSearch.getActionView(); - adapter.getFilter().filter(getUidForName(searchView.getQuery().toString())); + if (searchView != null) + query = getUidForName(searchView.getQuery().toString()); } + + if (TextUtils.isEmpty(query)) + adapter.changeCursor(DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked)); + else + adapter.changeCursor(DatabaseHelper.getInstance(ActivityLog.this).searchLog(query)); } } @@ -559,7 +566,7 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences. intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("application/octet-stream"); - intent.putExtra(Intent.EXTRA_TITLE, "netguard_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".pcap"); + intent.putExtra(Intent.EXTRA_TITLE, "networkgenie_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".pcap"); } return intent; } @@ -590,11 +597,11 @@ public class ActivityLog extends AppCompatActivity implements SharedPreferences. Uri target = data.getData(); if (data.hasExtra("org.openintents.extra.DIR_PATH")) - target = Uri.parse(target + "/netguard.pcap"); + target = Uri.parse(target + "/networkgenie.pcap"); Log.i(TAG, "Export PCAP URI=" + target); out = getContentResolver().openOutputStream(target); - File pcap = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); + File pcap = new File(getDir("data", MODE_PRIVATE), "networkgenie.pcap"); in = new FileInputStream(pcap); int len; diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityMain.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityMain.java similarity index 89% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityMain.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityMain.java index 2d3a406..ae21fe7 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityMain.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityMain.java @@ -1,24 +1,25 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ +import android.Manifest; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; @@ -63,6 +64,8 @@ import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SwitchCompat; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.preference.PreferenceManager; @@ -70,19 +73,20 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import java.io.File; +import java.net.MalformedURLException; +import java.net.URL; import java.util.List; public class ActivityMain extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.Main"; + private static final String TAG = "Networkgenie.Main"; private boolean running = false; private ImageView ivIcon; private ImageView ivQueue; - private SwitchCompat swEnabled; - private Button genieButton; - private TextView genieText; + private SwitchCompat swEnabled; private ImageView ivMetered; private SwipeRefreshLayout swipeRefresh; private AdapterRule adapter = null; @@ -97,22 +101,23 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences private static final int REQUEST_VPN = 1; private static final int REQUEST_INVITE = 2; - private static final int REQUEST_LOGCAT = 3; - public static final int REQUEST_ROAMING = 4; + public static final int REQUEST_ROAMING = 3; + private static final int REQUEST_NOTIFICATIONS = 4; private static final int MIN_SDK = Build.VERSION_CODES.LOLLIPOP_MR1; - public static final String ACTION_RULES_CHANGED = "eu.faircode.netguard.ACTION_RULES_CHANGED"; - public static final String ACTION_QUEUE_CHANGED = "eu.faircode.netguard.ACTION_QUEUE_CHANGED"; + public static final String ACTION_RULES_CHANGED = "com.breakpointingbad.networkgenie.ACTION_RULES_CHANGED"; + public static final String ACTION_QUEUE_CHANGED = "com.breakpointingbad.networkgenie.ACTION_QUEUE_CHANGED"; public static final String EXTRA_REFRESH = "Refresh"; public static final String EXTRA_SEARCH = "Search"; public static final String EXTRA_RELATED = "Related"; public static final String EXTRA_APPROVE = "Approve"; - public static final String EXTRA_LOGCAT = "Logcat"; public static final String EXTRA_CONNECTED = "Connected"; public static final String EXTRA_METERED = "Metered"; public static final String EXTRA_SIZE = "Size"; + private static final String MALWARE_URL = "https://urlhaus.abuse.ch/downloads/hostfile/"; + @Override protected void onCreate(Bundle savedInstanceState) { Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); @@ -162,6 +167,8 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences ivMetered = actionView.findViewById(R.id.ivMetered); genieButton = actionView.findViewById(R.id.genieButton); + genieButton.setOnClickListener(this::openGenie); + // Icon ivIcon.setOnLongClickListener(new View.OnLongClickListener() { @@ -175,7 +182,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences // Title getSupportActionBar().setTitle(null); - // Netguard is busy + // Networkgenie is busy ivQueue.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { @@ -191,8 +198,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences } }); - - // On/off switch swEnabled.setChecked(enabled); swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @@ -302,6 +307,17 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences TextView tvDisabled = findViewById(R.id.tvDisabled); tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE); + // Notification permissions + TextView tvNotifications = findViewById(R.id.tvNotifications); + tvNotifications.setVisibility(View.GONE); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) + tvNotifications.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, REQUEST_NOTIFICATIONS); + } + }); + // Application list RecyclerView rvApplication = findViewById(R.id.rvApplication); rvApplication.setHasFixedSize(false); @@ -372,7 +388,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED); intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); intentFilter.addDataScheme("package"); - registerReceiver(packageChangedReceiver, intentFilter); + ContextCompat.registerReceiver(this, packageChangedReceiver, intentFilter, ContextCompat.RECEIVER_NOT_EXPORTED); // First use if (!initialized) { @@ -511,7 +527,33 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences IAB.isPurchasedAny(this) || getIntentPro(this).resolveActivity(pm) == null ? View.GONE : View.VISIBLE); + boolean canNotify = + (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || + (ContextCompat.checkSelfPermission(this, + android.Manifest.permission.POST_NOTIFICATIONS) == + PackageManager.PERMISSION_GRANTED)); + TextView tvNotifications = findViewById(R.id.tvNotifications); + if (tvNotifications != null) + tvNotifications.setVisibility(canNotify ? View.GONE : View.VISIBLE); + super.onResume(); + + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R && false) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + if (!prefs.getBoolean("qap", false)) + if (Util.isPlayStoreInstall(this)) { + new AlertDialog.Builder(this) + .setMessage(R.string.app_qap) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + prefs.edit().putBoolean("qap", true).apply(); + } + }) + .show(); + } else + prefs.edit().putBoolean("qap", true).apply(); + } } @Override @@ -604,16 +646,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences } else if (requestCode == REQUEST_INVITE) { // Do nothing - } else if (requestCode == REQUEST_LOGCAT) { - // Send logcat by e-mail - if (resultCode == RESULT_OK) { - Uri target = data.getData(); - if (data.hasExtra("org.openintents.extra.DIR_PATH")) - target = Uri.parse(target + "/logcat.txt"); - Log.i(TAG, "Export URI=" + target); - Util.sendLogcat(target, this); - } - } else { Log.w(TAG, "Unknown activity result request=" + requestCode); super.onActivityResult(requestCode, resultCode, data); @@ -622,9 +654,23 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - if (requestCode == REQUEST_ROAMING) + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (requestCode == REQUEST_ROAMING) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) ServiceSinkhole.reload("permission granted", this, false); + } else if (requestCode == REQUEST_NOTIFICATIONS) { + if (grantResults[0] != PackageManager.PERMISSION_GRANTED && + !ActivityCompat.shouldShowRequestPermissionRationale(this, + Manifest.permission.POST_NOTIFICATIONS)) + try { + Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + Uri uri = Uri.fromParts("package", getPackageName(), null); + intent.setData(uri); + startActivity(intent); + } catch (Throwable ex) { + Log.e(TAG, ex + "\n" + ex.getStackTrace()); + } + } } @Override @@ -825,6 +871,8 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences public boolean onPrepareOptionsMenu(Menu menu) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + menu.findItem(R.id.menu_malware).setVisible(false); + if (prefs.getBoolean("manage_system", false)) { menu.findItem(R.id.menu_app_user).setChecked(prefs.getBoolean("show_user", true)); menu.findItem(R.id.menu_app_system).setChecked(prefs.getBoolean("show_system", false)); @@ -844,6 +892,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences menu.findItem(R.id.menu_sort_name).setChecked(true); menu.findItem(R.id.menu_lockdown).setChecked(prefs.getBoolean("lockdown", false)); + menu.findItem(R.id.menu_malware).setChecked(prefs.getBoolean("malware", false)); return super.onPrepareOptionsMenu(menu); } @@ -889,6 +938,10 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences menu_lockdown(item); return true; + case R.id.menu_malware: + menu_malware(item); + return true; + case R.id.menu_log: if (Util.canFilter(this)) if (IAB.isPurchased(ActivityPro.SKU_LOG, this)) @@ -985,13 +1038,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences Log.i(TAG, "Requesting VPN approval"); swEnabled.toggle(); } - - if (intent.hasExtra(EXTRA_LOGCAT)) { - Log.i(TAG, "Requesting logcat"); - Intent logcat = getIntentLogcat(); - if (logcat.resolveActivity(getPackageManager()) != null) - startActivityForResult(logcat, REQUEST_LOGCAT); - } } private void updateApplicationList(final String search) { @@ -1191,6 +1237,42 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences WidgetLockdown.updateWidgets(this); } + private void menu_malware(MenuItem item) { + item.setChecked(!item.isChecked()); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + prefs.edit().putBoolean("malware", item.isChecked()).apply(); + if (item.isChecked()) + try { + final File file = new File(getFilesDir(), "malware.txt"); + new DownloadTask(this, new URL(MALWARE_URL), file, new DownloadTask.Listener() { + @Override + public void onCompleted() { + prefs.edit().putBoolean("filter", true).apply(); + ServiceSinkhole.reload("malware download", ActivityMain.this, false); + } + + @Override + public void onCancelled() { + prefs.edit().putBoolean("malware", false).apply(); + } + + @Override + public void onException(Throwable ex) { + Toast.makeText(ActivityMain.this, ex.getMessage(), Toast.LENGTH_LONG).show(); + } + }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } catch (MalformedURLException ex) { + Toast.makeText(this, ex.toString(), Toast.LENGTH_LONG).show(); + } + else { + SharedPreferences.Editor editor = prefs.edit(); + for (String key : prefs.getAll().keySet()) + if (key.startsWith("malware.")) + editor.remove(key); + editor.apply(); + } + } + private void menu_about() { // Create view LayoutInflater inflater = LayoutInflater.from(this); @@ -1211,29 +1293,6 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences tvEula.setMovementMethod(LinkMovementMethod.getInstance()); tvPrivacy.setMovementMethod(LinkMovementMethod.getInstance()); - // Handle logcat - view.setOnClickListener(new View.OnClickListener() { - private short tap = 0; - private Toast toast = Toast.makeText(ActivityMain.this, "", Toast.LENGTH_SHORT); - - @Override - public void onClick(View view) { - tap++; - if (tap == 7) { - tap = 0; - toast.cancel(); - - Intent intent = getIntentLogcat(); - if (intent.resolveActivity(getPackageManager()) != null) - startActivityForResult(intent, REQUEST_LOGCAT); - - } else if (tap > 3) { - toast.setText(Integer.toString(7 - tap)); - toast.show(); - } - } - }); - // Handle rate btnRate.setVisibility(getIntentRate(this).resolveActivity(getPackageManager()) == null ? View.GONE : View.VISIBLE); btnRate.setOnClickListener(new View.OnClickListener() { @@ -1266,7 +1325,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences return new Intent(context, ActivityPro.class); else { Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("https://contact.faircode.eu/?product=netguardstandalone")); + intent.setData(Uri.parse("https://contact.bpb.com/?product=networkgeniestandalone")); return intent; } } @@ -1275,7 +1334,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.app_name)); - intent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.msg_try) + "\n\nhttps://www.netguard.me/\n\n"); + intent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.msg_try) + "\n\nhttps://www.networkgenie.me/\n\n"); return intent; } @@ -1292,25 +1351,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences private static Intent getIntentSupport() { Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md")); - return intent; - } - - private Intent getIntentLogcat() { - Intent intent; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - if (Util.isPackageInstalled("org.openintents.filemanager", this)) { - intent = new Intent("org.openintents.action.PICK_DIRECTORY"); - } else { - intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=org.openintents.filemanager")); - } - } else { - intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_TITLE, "logcat.txt"); - } + intent.setData(Uri.parse("https://github.com/M66B/Networkgenie/blob/master/FAQ.md")); return intent; } } diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityPro.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityPro.java similarity index 96% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityPro.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityPro.java index 063d360..4a1881f 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityPro.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivityPro.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.app.PendingIntent; @@ -51,7 +51,7 @@ import androidx.core.app.NavUtils; import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN; public class ActivityPro extends AppCompatActivity { - private static final String TAG = "NetGuard.Pro"; + private static final String TAG = "Networkgenie.Pro"; private IAB iab; @@ -145,7 +145,7 @@ public class ActivityPro extends AppCompatActivity { } Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("http://www.netguard.me/#" + sku)); + intent.setData(Uri.parse("http://www.networkgenie.me/#" + sku)); if (intent.resolveActivity(getPackageManager()) != null) startActivity(intent); } @@ -279,13 +279,18 @@ public class ActivityPro extends AppCompatActivity { @Override public boolean onPrepareOptionsMenu(Menu menu) { - if (IAB.isPurchased(SKU_DONATION, this) || Util.isPlayStoreInstall(this)) + if (Util.isPlayStoreInstall(this)) menu.removeItem(R.id.menu_challenge); return super.onPrepareOptionsMenu(menu); } private void menu_challenge() { + if (IAB.isPurchased(SKU_DONATION, this)) { + Toast.makeText(this, getString(R.string.title_pro_already), Toast.LENGTH_LONG).show(); + return; + } + LayoutInflater inflater = LayoutInflater.from(this); View view = inflater.inflate(R.layout.challenge, null, false); @@ -296,7 +301,7 @@ public class ActivityPro extends AppCompatActivity { String android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); final String challenge = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? Build.SERIAL : "O3" + android_id); - String seed = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "NetGuard2" : "NetGuard3"); + String seed = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "Networkgenie2" : "Networkgenie3"); // Challenge TextView tvChallenge = view.findViewById(R.id.tvChallenge); diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivitySettings.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivitySettings.java similarity index 95% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivitySettings.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivitySettings.java index 5c38150..666a0ba 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivitySettings.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ActivitySettings.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.Manifest; @@ -60,7 +60,9 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.app.ActivityCompat; import androidx.core.app.NavUtils; +import androidx.core.content.ContextCompat; import androidx.core.util.PatternsCompat; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.preference.PreferenceManager; @@ -94,7 +96,7 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParserFactory; public class ActivitySettings extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.Settings"; + private static final String TAG = "Networkgenie.Settings"; private boolean running = false; @@ -164,6 +166,17 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); List listSSID = new ArrayList<>(); + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + // TODO: Consider calling + // ActivityCompat#requestPermissions + // here to request the missing permissions, and then overriding + // public void onRequestPermissionsResult(int requestCode, String[] permissions, + // int[] grantResults) + // to handle the case where the user grants the permission. See the documentation + // for ActivityCompat#requestPermissions for more details. + System.out.println("unable to get all wifi permissions needed.."); + return; + } List configs = wm.getConfiguredNetworks(); if (configs != null) for (WifiConfiguration config : configs) @@ -368,7 +381,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url"); String hosts_url = pref_hosts_url.getText(); - if ("https://www.netguard.me/hosts".equals(hosts_url)) + if ("https://www.networkgenie.me/hosts".equals(hosts_url)) hosts_url = BuildConfig.HOSTS_FILE_URI; try { @@ -454,12 +467,12 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere IntentFilter ifInteractive = new IntentFilter(); ifInteractive.addAction(Intent.ACTION_SCREEN_ON); ifInteractive.addAction(Intent.ACTION_SCREEN_OFF); - registerReceiver(interactiveStateReceiver, ifInteractive); + ContextCompat.registerReceiver(this, interactiveStateReceiver, ifInteractive, ContextCompat.RECEIVER_NOT_EXPORTED); // Listen for connectivity updates IntentFilter ifConnectivity = new IntentFilter(); ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION); - registerReceiver(connectivityChangedReceiver, ifConnectivity); + ContextCompat.registerReceiver(this, connectivityChangedReceiver, ifConnectivity, ContextCompat.RECEIVER_NOT_EXPORTED); } @Override @@ -751,7 +764,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere ServiceSinkhole.setPcap(false, this); - File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); + File pcap_file = new File(getDir("data", MODE_PRIVATE), "networkgenie.pcap"); if (pcap_file.exists() && !pcap_file.delete()) Log.w(TAG, "Delete PCAP failed"); @@ -800,6 +813,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); PreferenceScreen screen = getPreferenceScreen(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -912,7 +926,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); // text/xml - intent.putExtra(Intent.EXTRA_TITLE, "netguard_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml"); + intent.putExtra(Intent.EXTRA_TITLE, "networkgenie_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml"); } return intent; } @@ -947,7 +961,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere try { Uri target = data.getData(); if (data.hasExtra("org.openintents.extra.DIR_PATH")) - target = Uri.parse(target + "/netguard_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml"); + target = Uri.parse(target + "/networkgenie_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml"); Log.i(TAG, "Writing URI=" + target); out = getContentResolver().openOutputStream(target); xmlExport(out); @@ -1091,7 +1105,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere serializer.setOutput(out, "UTF-8"); serializer.startDocument(null, true); serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); - serializer.startTag(null, "netguard"); + serializer.startTag(null, "networkgenie"); serializer.startTag(null, "application"); xmlExport(PreferenceManager.getDefaultSharedPreferences(this), serializer); @@ -1137,7 +1151,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere forwardExport(serializer); serializer.endTag(null, "forward"); - serializer.endTag(null, "netguard"); + serializer.endTag(null, "networkgenie"); serializer.endDocument(); serializer.flush(); } @@ -1186,13 +1200,13 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere private void filterExport(XmlSerializer serializer) throws IOException { try (Cursor cursor = DatabaseHelper.getInstance(this).getAccess()) { - int colUid = cursor.getColumnIndex("uid"); - int colVersion = cursor.getColumnIndex("version"); - int colProtocol = cursor.getColumnIndex("protocol"); - int colDAddr = cursor.getColumnIndex("daddr"); - int colDPort = cursor.getColumnIndex("dport"); - int colTime = cursor.getColumnIndex("time"); - int colBlock = cursor.getColumnIndex("block"); + int colUid = cursor.getColumnIndexOrThrow("uid"); + int colVersion = cursor.getColumnIndexOrThrow("version"); + int colProtocol = cursor.getColumnIndexOrThrow("protocol"); + int colDAddr = cursor.getColumnIndexOrThrow("daddr"); + int colDPort = cursor.getColumnIndexOrThrow("dport"); + int colTime = cursor.getColumnIndexOrThrow("time"); + int colBlock = cursor.getColumnIndexOrThrow("block"); while (cursor.moveToNext()) for (String pkg : getPackages(cursor.getInt(colUid))) { serializer.startTag(null, "rule"); @@ -1210,11 +1224,11 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere private void forwardExport(XmlSerializer serializer) throws IOException { try (Cursor cursor = DatabaseHelper.getInstance(this).getForwarding()) { - int colProtocol = cursor.getColumnIndex("protocol"); - int colDPort = cursor.getColumnIndex("dport"); - int colRAddr = cursor.getColumnIndex("raddr"); - int colRPort = cursor.getColumnIndex("rport"); - int colRUid = cursor.getColumnIndex("ruid"); + int colProtocol = cursor.getColumnIndexOrThrow("protocol"); + int colDPort = cursor.getColumnIndexOrThrow("dport"); + int colRAddr = cursor.getColumnIndexOrThrow("raddr"); + int colRPort = cursor.getColumnIndexOrThrow("rport"); + int colRUid = cursor.getColumnIndexOrThrow("ruid"); while (cursor.moveToNext()) for (String pkg : getPackages(cursor.getInt(colRUid))) { serializer.startTag(null, "port"); @@ -1321,7 +1335,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere @Override public void startElement(String uri, String localName, String qName, Attributes attributes) { - if (qName.equals("netguard")) + if (qName.equals("networkgenie")) ; // Ignore else if (qName.equals("application")) diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterAccess.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterAccess.java similarity index 86% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterAccess.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterAccess.java index 1ddbc11..6c1825d 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterAccess.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterAccess.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.Context; @@ -62,17 +62,17 @@ public class AdapterAccess extends CursorAdapter { public AdapterAccess(Context context, Cursor cursor) { super(context, cursor, 0); - colVersion = cursor.getColumnIndex("version"); - colProtocol = cursor.getColumnIndex("protocol"); - colDaddr = cursor.getColumnIndex("daddr"); - colDPort = cursor.getColumnIndex("dport"); - colTime = cursor.getColumnIndex("time"); - colAllowed = cursor.getColumnIndex("allowed"); - colBlock = cursor.getColumnIndex("block"); - colCount = cursor.getColumnIndex("count"); - colSent = cursor.getColumnIndex("sent"); - colReceived = cursor.getColumnIndex("received"); - colConnections = cursor.getColumnIndex("connections"); + colVersion = cursor.getColumnIndexOrThrow("version"); + colProtocol = cursor.getColumnIndexOrThrow("protocol"); + colDaddr = cursor.getColumnIndexOrThrow("daddr"); + colDPort = cursor.getColumnIndexOrThrow("dport"); + colTime = cursor.getColumnIndexOrThrow("time"); + colAllowed = cursor.getColumnIndexOrThrow("allowed"); + colBlock = cursor.getColumnIndexOrThrow("block"); + colCount = cursor.getColumnIndexOrThrow("count"); + colSent = cursor.getColumnIndexOrThrow("sent"); + colReceived = cursor.getColumnIndexOrThrow("received"); + colConnections = cursor.getColumnIndexOrThrow("connections"); TypedArray ta = context.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorSecondary}); try { diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterDns.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterDns.java similarity index 76% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterDns.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterDns.java index 6ddd7e6..bd2c351 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterDns.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterDns.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.Context; @@ -42,6 +42,7 @@ public class AdapterDns extends CursorAdapter { private int colAName; private int colResource; private int colTTL; + private int colUid; public AdapterDns(Context context, Cursor cursor) { super(context, cursor, 0); @@ -53,11 +54,12 @@ public class AdapterDns extends CursorAdapter { else colorExpired = Color.argb(128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY), Color.blue(Color.LTGRAY)); - colTime = cursor.getColumnIndex("time"); - colQName = cursor.getColumnIndex("qname"); - colAName = cursor.getColumnIndex("aname"); - colResource = cursor.getColumnIndex("resource"); - colTTL = cursor.getColumnIndex("ttl"); + colTime = cursor.getColumnIndexOrThrow("time"); + colQName = cursor.getColumnIndexOrThrow("qname"); + colAName = cursor.getColumnIndexOrThrow("aname"); + colResource = cursor.getColumnIndexOrThrow("resource"); + colTTL = cursor.getColumnIndexOrThrow("ttl"); + colUid = cursor.getColumnIndexOrThrow("uid"); } @Override @@ -73,6 +75,7 @@ public class AdapterDns extends CursorAdapter { String aname = cursor.getString(colAName); String resource = cursor.getString(colResource); int ttl = cursor.getInt(colTTL); + int uid = cursor.getInt(colUid); long now = new Date().getTime(); boolean expired = (time + ttl < now); @@ -84,6 +87,7 @@ public class AdapterDns extends CursorAdapter { TextView tvAName = view.findViewById(R.id.tvAName); TextView tvResource = view.findViewById(R.id.tvResource); TextView tvTTL = view.findViewById(R.id.tvTTL); + TextView tvUid = view.findViewById(R.id.tvUid); // Set values tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time)); @@ -91,5 +95,6 @@ public class AdapterDns extends CursorAdapter { tvAName.setText(aname); tvResource.setText(resource); tvTTL.setText("+" + Integer.toString(ttl / 1000)); + tvUid.setText(uid > 0 ? Integer.toString(uid) : null); } } diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterForwarding.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterForwarding.java similarity index 77% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterForwarding.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterForwarding.java index 44ceaa0..99e9d57 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterForwarding.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterForwarding.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.Context; @@ -37,11 +37,11 @@ public class AdapterForwarding extends CursorAdapter { public AdapterForwarding(Context context, Cursor cursor) { super(context, cursor, 0); - colProtocol = cursor.getColumnIndex("protocol"); - colDPort = cursor.getColumnIndex("dport"); - colRAddr = cursor.getColumnIndex("raddr"); - colRPort = cursor.getColumnIndex("rport"); - colRUid = cursor.getColumnIndex("ruid"); + colProtocol = cursor.getColumnIndexOrThrow("protocol"); + colDPort = cursor.getColumnIndexOrThrow("dport"); + colRAddr = cursor.getColumnIndexOrThrow("raddr"); + colRPort = cursor.getColumnIndexOrThrow("rport"); + colRUid = cursor.getColumnIndexOrThrow("ruid"); } @Override diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterLog.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterLog.java similarity index 85% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterLog.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterLog.java index 892bf79..e6dafc5 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterLog.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterLog.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.Context; @@ -48,7 +48,7 @@ import java.text.SimpleDateFormat; import java.util.List; public class AdapterLog extends CursorAdapter { - private static String TAG = "NetGuard.Log"; + private static String TAG = "Networkgenie.Log"; private boolean resolve; private boolean organization; @@ -78,20 +78,20 @@ public class AdapterLog extends CursorAdapter { super(context, cursor, 0); this.resolve = resolve; this.organization = organization; - colTime = cursor.getColumnIndex("time"); - colVersion = cursor.getColumnIndex("version"); - colProtocol = cursor.getColumnIndex("protocol"); - colFlags = cursor.getColumnIndex("flags"); - colSAddr = cursor.getColumnIndex("saddr"); - colSPort = cursor.getColumnIndex("sport"); - colDAddr = cursor.getColumnIndex("daddr"); - colDPort = cursor.getColumnIndex("dport"); - colDName = cursor.getColumnIndex("dname"); - colUid = cursor.getColumnIndex("uid"); - colData = cursor.getColumnIndex("data"); - colAllowed = cursor.getColumnIndex("allowed"); - colConnection = cursor.getColumnIndex("connection"); - colInteractive = cursor.getColumnIndex("interactive"); + colTime = cursor.getColumnIndexOrThrow("time"); + colVersion = cursor.getColumnIndexOrThrow("version"); + colProtocol = cursor.getColumnIndexOrThrow("protocol"); + colFlags = cursor.getColumnIndexOrThrow("flags"); + colSAddr = cursor.getColumnIndexOrThrow("saddr"); + colSPort = cursor.getColumnIndexOrThrow("sport"); + colDAddr = cursor.getColumnIndexOrThrow("daddr"); + colDPort = cursor.getColumnIndexOrThrow("dport"); + colDName = cursor.getColumnIndexOrThrow("dname"); + colUid = cursor.getColumnIndexOrThrow("uid"); + colData = cursor.getColumnIndexOrThrow("data"); + colAllowed = cursor.getColumnIndexOrThrow("allowed"); + colConnection = cursor.getColumnIndexOrThrow("connection"); + colInteractive = cursor.getColumnIndexOrThrow("interactive"); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorOn, tv, true); @@ -206,7 +206,21 @@ public class AdapterLog extends CursorAdapter { // Application icon ApplicationInfo info = null; PackageManager pm = context.getPackageManager(); - String[] pkg = pm.getPackagesForUid(uid); + String[] pkg = null; + + try { + pkg = pm.getPackagesForUid(uid); + } catch (SecurityException ignored) { + // STACK_TRACE=java.lang.SecurityException: getPackagesForUid: UID 1010154 requires android.permission.INTERACT_ACROSS_USERS_FULL or android.permission.INTERACT_ACROSS_USERS to access user 0. + // at android.os.Parcel.createExceptionOrNull(Parcel.java:3240) + // at android.os.Parcel.createException(Parcel.java:3224) + // at android.os.Parcel.readException(Parcel.java:3200) + // at android.os.Parcel.readException(Parcel.java:3142) + // at android.content.pm.IPackageManager$Stub$Proxy.getPackagesForUid(IPackageManager.java:5176) + // at android.app.ApplicationPackageManager$3.recompute(ApplicationPackageManager.java:1148) + // at android.app.ApplicationPackageManager$3.recompute(ApplicationPackageManager.java:1142) + } + if (pkg != null && pkg.length > 0) try { info = pm.getApplicationInfo(pkg[0], 0); diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterRule.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterRule.java similarity index 98% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterRule.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterRule.java index 81b1dd3..e51b4f5 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterRule.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/AdapterRule.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.annotation.TargetApi; @@ -78,7 +78,7 @@ import java.util.Arrays; import java.util.List; public class AdapterRule extends RecyclerView.Adapter implements Filterable { - private static final String TAG = "NetGuard.Adapter"; + private static final String TAG = "Networkgenie.Adapter"; private View anchor; private LayoutInflater inflater; @@ -703,13 +703,13 @@ public class AdapterRule extends RecyclerView.Adapter im public void onItemClick(AdapterView parent, View view, final int bposition, long bid) { PackageManager pm = context.getPackageManager(); Cursor cursor = (Cursor) badapter.getItem(bposition); - final long id = cursor.getLong(cursor.getColumnIndex("ID")); - final int version = cursor.getInt(cursor.getColumnIndex("version")); - final int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); - final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); - final int dport = cursor.getInt(cursor.getColumnIndex("dport")); - long time = cursor.getLong(cursor.getColumnIndex("time")); - int block = cursor.getInt(cursor.getColumnIndex("block")); + final long id = cursor.getLong(cursor.getColumnIndexOrThrow("ID")); + final int version = cursor.getInt(cursor.getColumnIndexOrThrow("version")); + final int protocol = cursor.getInt(cursor.getColumnIndexOrThrow("protocol")); + final String daddr = cursor.getString(cursor.getColumnIndexOrThrow("daddr")); + final int dport = cursor.getInt(cursor.getColumnIndexOrThrow("dport")); + long time = cursor.getLong(cursor.getColumnIndexOrThrow("time")); + int block = cursor.getInt(cursor.getColumnIndexOrThrow("block")); PopupMenu popup = new PopupMenu(context, anchor); popup.inflate(R.menu.access); @@ -795,7 +795,7 @@ public class AdapterRule extends RecyclerView.Adapter im case R.id.menu_copy: ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("netguard", daddr); + ClipData clip = ClipData.newPlainText("networkgenie", daddr); clipboard.setPrimaryClip(clip); return true; } diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Allowed.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Allowed.java similarity index 60% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Allowed.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Allowed.java index c854d38..147982f 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Allowed.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Allowed.java @@ -1,31 +1,37 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ public class Allowed { public String raddr; public int rport; + public int bypass; + public String sender; + public Allowed() { this.raddr = null; this.rport = 0; + + this.bypass = 1; + this.sender = "blahh"; } public Allowed(String raddr, int rport) { diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ApplicationEx.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ApplicationEx.java similarity index 80% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/ApplicationEx.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ApplicationEx.java index 3b7e0da..34081f4 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ApplicationEx.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ApplicationEx.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.annotation.TargetApi; @@ -29,7 +29,7 @@ import android.os.Build; import android.util.Log; public class ApplicationEx extends Application { - private static final String TAG = "NetGuard.App"; + private static final String TAG = "Networkgenie.App"; private Thread.UncaughtExceptionHandler mPrevHandler; @@ -74,5 +74,10 @@ public class ApplicationEx extends Application { access.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT); access.setBypassDnd(true); nm.createNotificationChannel(access); + + NotificationChannel malware = new NotificationChannel("malware", getString(R.string.setting_malware), NotificationManager.IMPORTANCE_HIGH); + malware.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT); + malware.setBypassDnd(true); + nm.createNotificationChannel(malware); } } diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/DatabaseHelper.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/DatabaseHelper.java similarity index 94% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/DatabaseHelper.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/DatabaseHelper.java index 47c0b9a..a3c8ab6 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/DatabaseHelper.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/DatabaseHelper.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.ContentValues; @@ -43,10 +43,10 @@ import java.util.Map; import java.util.concurrent.locks.ReentrantReadWriteLock; public class DatabaseHelper extends SQLiteOpenHelper { - private static final String TAG = "NetGuard.Database"; + private static final String TAG = "Networkgenie.Database"; - private static final String DB_NAME = "Netguard"; - private static final int DB_VERSION = 21; + private static final String DB_NAME = "Networkgenie"; + private static final int DB_VERSION = 22; private static boolean once = true; private static List logChangedListeners = new ArrayList<>(); @@ -62,6 +62,8 @@ public class DatabaseHelper extends SQLiteOpenHelper { private final static int MSG_ACCESS = 2; private final static int MSG_FORWARD = 3; + private final static long SYN_SNI_DELAY = 5000L; + private SharedPreferences prefs; private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); @@ -188,6 +190,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { ", aname TEXT NOT NULL" + ", resource TEXT NOT NULL" + ", ttl INTEGER" + + ", uid INTEGER" + ");"); db.execSQL("CREATE UNIQUE INDEX idx_dns ON dns(qname, aname, resource)"); db.execSQL("CREATE INDEX idx_dns_resource ON dns(resource)"); @@ -223,7 +226,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { Cursor cursor = null; try { cursor = db.rawQuery("SELECT * FROM " + table + " LIMIT 0", null); - return (cursor.getColumnIndex(column) >= 0); + return (cursor.getColumnIndexOrThrow(column) >= 0); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); return false; @@ -347,6 +350,12 @@ public class DatabaseHelper extends SQLiteOpenHelper { oldVersion = 21; } + if (oldVersion < 22) { + if (!columnExists(db, "dns", "uid")) + db.execSQL("ALTER TABLE dns ADD COLUMN uid INTEGER"); + oldVersion = 22; + } + if (oldVersion == DB_VERSION) { db.setVersion(oldVersion); db.setTransactionSuccessful(); @@ -369,6 +378,29 @@ public class DatabaseHelper extends SQLiteOpenHelper { SQLiteDatabase db = this.getWritableDatabase(); db.beginTransactionNonExclusive(); try { + if (packet.protocol == 6 /* TCP */ && + packet.daddr != null && + packet.dport > 0 && + packet.uid > 0 && + "sni".equals(packet.data)) { + int deleted = db.delete("log", "time > ?" + + " AND protocol = ?" + + " AND version = ?" + + " AND flags = ?" + + " AND daddr = ?" + + " AND dport = ?" + + " AND uid = ?", + new String[]{ + Long.toString(packet.time - SYN_SNI_DELAY), + Integer.toString(packet.protocol), + Integer.toString(packet.version), + "S", // SYN + packet.daddr, + Integer.toString(packet.dport), + Integer.toString(packet.uid) + }); + Log.i(TAG, "Deleted=" + deleted + " packet=" + packet + " dname=" + dname); + } ContentValues cv = new ContentValues(); cv.put("time", packet.time); cv.put("version", packet.version); @@ -582,9 +614,9 @@ public class DatabaseHelper extends SQLiteOpenHelper { long sent = 0; long received = 0; int connections = 0; - int colSent = cursor.getColumnIndex("sent"); - int colReceived = cursor.getColumnIndex("received"); - int colConnections = cursor.getColumnIndex("connections"); + int colSent = cursor.getColumnIndexOrThrow("sent"); + int colReceived = cursor.getColumnIndexOrThrow("received"); + int colConnections = cursor.getColumnIndexOrThrow("connections"); if (cursor.moveToNext()) { sent = cursor.isNull(colSent) ? 0 : cursor.getLong(colSent); received = cursor.isNull(colReceived) ? 0 : cursor.getLong(colReceived); @@ -803,6 +835,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { cv.put("qname", rr.QName); cv.put("aname", rr.AName); cv.put("resource", rr.Resource); + cv.put("uid", rr.uid); if (db.insert("dns", null, cv) == -1) Log.e(TAG, "Insert dns failed"); @@ -867,7 +900,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { String query = "SELECT d.qname"; query += " FROM dns AS d"; query += " WHERE d.resource = '" + ip.replace("'", "''") + "'"; - query += " ORDER BY d.qname"; + query += " ORDER BY (d.uid = " + uid + ") DESC, d.qname"; query += " LIMIT 1"; // There is no way to known for sure which domain name an app used, so just pick the first one return db.compileStatement(query).simpleQueryForString(); diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/DownloadTask.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/DownloadTask.java similarity index 77% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/DownloadTask.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/DownloadTask.java index ca74ade..40e6d2f 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/DownloadTask.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/DownloadTask.java @@ -1,28 +1,29 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.app.Activity; import android.app.PendingIntent; import android.content.Context; import android.content.Intent; +import android.content.pm.PackageManager; import android.os.AsyncTask; import android.os.Build; import android.os.PowerManager; @@ -30,6 +31,7 @@ import android.util.Log; import android.util.TypedValue; import android.widget.Toast; +import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; @@ -43,7 +45,7 @@ import java.net.URL; import java.net.URLConnection; public class DownloadTask extends AsyncTask { - private static final String TAG = "NetGuard.Download"; + private static final String TAG = "Networkgenie.Download"; private Context context; private URL url; @@ -72,7 +74,8 @@ public class DownloadTask extends AsyncTask { wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); wakeLock.acquire(); showNotification(0); - Toast.makeText(context, context.getString(R.string.msg_downloading, url.toString()), Toast.LENGTH_SHORT).show(); + if (!Util.isPlayStoreInstall(context)) + Toast.makeText(context, context.getString(R.string.msg_downloading, url.toString()), Toast.LENGTH_SHORT).show(); } @Override @@ -157,7 +160,7 @@ public class DownloadTask extends AsyncTask { private void showNotification(int progress) { Intent main = new Intent(context, ActivitySettings.class); - PendingIntent pi = PendingIntent.getActivity(context, ServiceSinkhole.NOTIFY_DOWNLOAD, main, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(context, ServiceSinkhole.NOTIFY_DOWNLOAD, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); @@ -175,7 +178,17 @@ public class DownloadTask extends AsyncTask { builder.setCategory(NotificationCompat.CATEGORY_STATUS) .setVisibility(NotificationCompat.VISIBILITY_SECRET); - NotificationManagerCompat.from(context).notify(ServiceSinkhole.NOTIFY_DOWNLOAD, builder.build()); + if (Util.canNotify(context)) + if (ActivityCompat.checkSelfPermission(context, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { + // TODO: Consider calling + // ActivityCompat#requestPermissions + // here to request the missing permissions, and then overriding + // public void onRequestPermissionsResult(int requestCode, String[] permissions, + // int[] grantResults) + // to handle the case where the user grants the permission. See the documentation + // for ActivityCompat#requestPermissions for more details. + return; + } + NotificationManagerCompat.from(context).notify(ServiceSinkhole.NOTIFY_DOWNLOAD, builder.build()); } - } diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ExpandedListView.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ExpandedListView.java similarity index 77% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ExpandedListView.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ExpandedListView.java index ba3a684..dcdb5b3 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ExpandedListView.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ExpandedListView.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.Context; diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Forward.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Forward.java similarity index 68% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Forward.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Forward.java index 675d782..37e2980 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Forward.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Forward.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ public class Forward { diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/FragmentSettings.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/FragmentSettings.java similarity index 68% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/FragmentSettings.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/FragmentSettings.java index df8b3d3..618c0b9 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/FragmentSettings.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/FragmentSettings.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.os.Bundle; diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/GenieActivity.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/GenieActivity.java similarity index 99% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/GenieActivity.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/GenieActivity.java index 3af370a..d80c65f 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/GenieActivity.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/GenieActivity.java @@ -1,4 +1,4 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; import androidx.appcompat.app.AppCompatActivity; diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/GlideHelper.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/GlideHelper.java similarity index 79% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/GlideHelper.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/GlideHelper.java index a10561e..18e4497 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/GlideHelper.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/GlideHelper.java @@ -1,4 +1,4 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; import com.bumptech.glide.annotation.GlideModule; import com.bumptech.glide.module.AppGlideModule; diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/IAB.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/IAB.java similarity index 94% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/IAB.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/IAB.java index 86b0dd1..e2a3fbf 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/IAB.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/IAB.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.app.PendingIntent; @@ -41,7 +41,7 @@ import java.util.ArrayList; import java.util.List; public class IAB implements ServiceConnection { - private static final String TAG = "NetGuard.IAB"; + private static final String TAG = "Networkgenie.IAB"; private Context context; private Delegate delegate; @@ -157,7 +157,7 @@ public class IAB implements ServiceConnection { public PendingIntent getBuyIntent(String sku, boolean subscription) throws RemoteException { if (service == null) return null; - Bundle bundle = service.getBuyIntent(IAB_VERSION, context.getPackageName(), sku, subscription ? "subs" : "inapp", "netguard"); + Bundle bundle = service.getBuyIntent(IAB_VERSION, context.getPackageName(), sku, subscription ? "subs" : "inapp", "networkgenie"); Log.i(TAG, "getBuyIntent sku=" + sku + " subscription=" + subscription); Util.logBundle(bundle); int response = (bundle == null ? -1 : bundle.getInt("RESPONSE_CODE", -1)); diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/IPUtil.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/IPUtil.java similarity index 90% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/IPUtil.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/IPUtil.java index e18170d..b786f6f 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/IPUtil.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/IPUtil.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.util.Log; @@ -29,7 +29,7 @@ import java.util.ArrayList; import java.util.List; public class IPUtil { - private static final String TAG = "NetGuard.IPUtil"; + private static final String TAG = "Networkgenie.IPUtil"; public static List toCIDR(String start, String end) throws UnknownHostException { return toCIDR(InetAddress.getByName(start), InetAddress.getByName(end)); diff --git a/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/MainActivity.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/MainActivity.java new file mode 100644 index 0000000..a1ab56e --- /dev/null +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/MainActivity.java @@ -0,0 +1,24 @@ +package com.breakpointingbad.networkgenie; + +import android.os.Bundle; + +import androidx.activity.EdgeToEdge; +import androidx.appcompat.app.AppCompatActivity; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowInsetsCompat; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + EdgeToEdge.enable(this); + setContentView(R.layout.activity_main); + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> { + Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); + return insets; + }); + } +} \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Packet.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Packet.java similarity index 72% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Packet.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Packet.java index 5460add..d571279 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Packet.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Packet.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ public class Packet { diff --git a/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/PendingIntentCompat.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/PendingIntentCompat.java new file mode 100644 index 0000000..860dcb5 --- /dev/null +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/PendingIntentCompat.java @@ -0,0 +1,66 @@ +package com.breakpointingbad.networkgenie; + +/* + This file is part of Networkgenie. + + Networkgenie 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. + + Networkgenie 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 Networkgenie. If not, see . + + Copyright 2015-2024 by Marcel Bokhorst (M66B) +*/ + +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.util.Log; + +import androidx.annotation.NonNull; + +public class PendingIntentCompat { + private PendingIntentCompat() { + } + + // https://developer.android.com/about/versions/12/behavior-changes-12#pending-intent-mutability + + // Xiaomi Android 11: Too many PendingIntent created for uid nnnnn + // https://stackoverflow.com/questions/71266853/xiaomi-android-11-securityexception-too-many-pendingintent-created + + public static PendingIntent getActivity(Context context, int requestCode, Intent intent, int flags) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || (flags & PendingIntent.FLAG_MUTABLE) != 0) + return PendingIntent.getActivity(context, requestCode, intent, flags); + else + return PendingIntent.getActivity(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); + } + + public static PendingIntent getService(Context context, int requestCode, @NonNull Intent intent, int flags) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || (flags & PendingIntent.FLAG_MUTABLE) != 0) + return PendingIntent.getService(context, requestCode, intent, flags); + else + return PendingIntent.getService(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); + } + + static PendingIntent getForegroundService(Context context, int requestCode, @NonNull Intent intent, int flags) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || (flags & PendingIntent.FLAG_MUTABLE) != 0) + return PendingIntent.getService(context, requestCode, intent, flags); + else + return PendingIntent.getForegroundService(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); + } + + static PendingIntent getBroadcast(Context context, int requestCode, Intent intent, int flags) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S || (flags & PendingIntent.FLAG_MUTABLE) != 0) + return PendingIntent.getBroadcast(context, requestCode, intent, flags); + else + return PendingIntent.getBroadcast(context, requestCode, intent, flags | PendingIntent.FLAG_IMMUTABLE); + } +} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ReceiverAutostart.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ReceiverAutostart.java similarity index 92% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/ReceiverAutostart.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ReceiverAutostart.java index 75aad2a..d12ebbd 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ReceiverAutostart.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ReceiverAutostart.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.BroadcastReceiver; @@ -31,7 +31,7 @@ import androidx.preference.PreferenceManager; import java.util.Map; public class ReceiverAutostart extends BroadcastReceiver { - private static final String TAG = "NetGuard.Receiver"; + private static final String TAG = "Networkgenie.Receiver"; @Override public void onReceive(final Context context, Intent intent) { diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ReceiverPackageRemoved.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ReceiverPackageRemoved.java similarity index 78% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/ReceiverPackageRemoved.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ReceiverPackageRemoved.java index d8ebf9a..1fc0f37 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ReceiverPackageRemoved.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ReceiverPackageRemoved.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.BroadcastReceiver; @@ -27,7 +27,7 @@ import android.util.Log; import androidx.core.app.NotificationManagerCompat; public class ReceiverPackageRemoved extends BroadcastReceiver { - private static final String TAG = "NetGuard.Receiver"; + private static final String TAG = "Networkgenie.Receiver"; @Override public void onReceive(final Context context, Intent intent) { diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ResourceRecord.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ResourceRecord.java similarity index 73% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ResourceRecord.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ResourceRecord.java index 0d689d1..cabe727 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ResourceRecord.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ResourceRecord.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import java.text.DateFormat; @@ -29,6 +29,7 @@ public class ResourceRecord { public String AName; public String Resource; public int TTL; + public int uid; private static DateFormat formatter = SimpleDateFormat.getDateTimeInstance(); @@ -42,6 +43,7 @@ public class ResourceRecord { " A " + AName + " R " + Resource + " TTL " + TTL + + " uid " + uid + " " + formatter.format(new Date(Time + TTL * 1000L).getTime()); } } diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Rule.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Rule.java similarity index 97% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/Rule.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Rule.java index e2e2b6e..158663b 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Rule.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Rule.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.Context; @@ -45,7 +45,7 @@ import java.util.Locale; import java.util.Map; public class Rule { - private static final String TAG = "NetGuard.Rule"; + private static final String TAG = "Networkgenie.Rule"; public int uid; public String packageName; @@ -181,10 +181,10 @@ public class Rule { try { cursor = dh.getApp(this.packageName); if (cursor.moveToNext()) { - this.name = cursor.getString(cursor.getColumnIndex("label")); - this.system = cursor.getInt(cursor.getColumnIndex("system")) > 0; - this.internet = cursor.getInt(cursor.getColumnIndex("internet")) > 0; - this.enabled = cursor.getInt(cursor.getColumnIndex("enabled")) > 0; + this.name = cursor.getString(cursor.getColumnIndexOrThrow("label")); + this.system = cursor.getInt(cursor.getColumnIndexOrThrow("system")) > 0; + this.internet = cursor.getInt(cursor.getColumnIndexOrThrow("internet")) > 0; + this.enabled = cursor.getInt(cursor.getColumnIndexOrThrow("enabled")) > 0; } else { this.name = getLabel(info, context); this.system = isSystem(info.packageName, context); diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceExternal.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceExternal.java similarity index 88% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceExternal.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceExternal.java index 3330548..9f084dc 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceExternal.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceExternal.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.app.IntentService; @@ -41,10 +41,10 @@ import java.text.SimpleDateFormat; import java.util.Date; public class ServiceExternal extends IntentService { - private static final String TAG = "NetGuard.External"; - private static final String ACTION_DOWNLOAD_HOSTS_FILE = "eu.faircode.netguard.DOWNLOAD_HOSTS_FILE"; + private static final String TAG = "Networkgenie.External"; + private static final String ACTION_DOWNLOAD_HOSTS_FILE = "com.breakpointingbad.networkgenie.DOWNLOAD_HOSTS_FILE"; - // am startservice -a eu.faircode.netguard.DOWNLOAD_HOSTS_FILE + // am startservice -a com.breakpointingbad.networkgenie.DOWNLOAD_HOSTS_FILE public ServiceExternal() { super(TAG); @@ -62,7 +62,7 @@ public class ServiceExternal extends IntentService { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String hosts_url = prefs.getString("hosts_url", null); - if ("https://www.netguard.me/hosts".equals(hosts_url)) + if ("https://www.networkgenie.me/hosts".equals(hosts_url)) hosts_url = BuildConfig.HOSTS_FILE_URI; File tmp = new File(getFilesDir(), "hosts.tmp"); diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceSinkhole.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceSinkhole.java similarity index 82% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceSinkhole.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceSinkhole.java index 7c08cb4..7ade59b 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceSinkhole.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceSinkhole.java @@ -1,26 +1,27 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.annotation.TargetApi; import android.app.AlarmManager; +import android.app.ForegroundServiceStartNotAllowedException; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -70,6 +71,7 @@ import android.util.Pair; import android.util.TypedValue; import android.widget.RemoteViews; +import androidx.core.app.ActivityCompat; import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationManagerCompat; import androidx.core.content.ContextCompat; @@ -103,6 +105,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.TreeMap; import java.util.concurrent.ExecutorService; @@ -112,7 +115,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import javax.net.ssl.HttpsURLConnection; public class ServiceSinkhole extends VpnService implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.Service"; + private static final String TAG = "Networkgenie.Service"; private boolean registeredUser = false; private boolean registeredIdleState = false; @@ -135,6 +138,12 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS private int last_blocked = -1; private int last_hosts = -1; + private static String genieInfo = "none"; + private static String sendType = "none"; + private static String sendConn = "none"; + private static String currConnInfo = "none"; + private static String currGenieDestIp = "1.1.1.1"; //207.x + private static Object jni_lock = new Object(); private static long jni_context = 0; private Thread tunnelThread = null; @@ -143,7 +152,9 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS private boolean temporarilyStopped = false; private long last_hosts_modified = 0; + private long last_malware_modified = 0; private Map mapHostsBlocked = new HashMap<>(); + private Map mapMalware = new HashMap<>(); private Map mapUidAllowed = new HashMap<>(); private Map mapUidKnown = new HashMap<>(); private final Map> mapUidIPFilters = new HashMap<>(); @@ -192,9 +203,9 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS private ExecutorService executor = Executors.newCachedThreadPool(); - private static final String ACTION_HOUSE_HOLDING = "eu.faircode.netguard.HOUSE_HOLDING"; - private static final String ACTION_SCREEN_OFF_DELAYED = "eu.faircode.netguard.SCREEN_OFF_DELAYED"; - private static final String ACTION_WATCHDOG = "eu.faircode.netguard.WATCHDOG"; + private static final String ACTION_HOUSE_HOLDING = "com.breakpointingbad.networkgenie.HOUSE_HOLDING"; + private static final String ACTION_SCREEN_OFF_DELAYED = "com.breakpointingbad.networkgenie.SCREEN_OFF_DELAYED"; + private static final String ACTION_WATCHDOG = "com.breakpointingbad.networkgenie.WATCHDOG"; private native long jni_init(int sdk); @@ -239,7 +250,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } - File pcap = (enabled ? new File(context.getDir("data", MODE_PRIVATE), "netguard.pcap") : null); + File pcap = (enabled ? new File(context.getDir("data", MODE_PRIVATE), "networkgenie.pcap") : null); jni_pcap(pcap == null ? null : pcap.getAbsolutePath(), record_size, file_size); } @@ -346,7 +357,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS ifInteractive.addAction(Intent.ACTION_SCREEN_ON); ifInteractive.addAction(Intent.ACTION_SCREEN_OFF); ifInteractive.addAction(ACTION_SCREEN_OFF_DELAYED); - registerReceiver(interactiveStateReceiver, ifInteractive); + ContextCompat.registerReceiver(ServiceSinkhole.this, interactiveStateReceiver, ifInteractive, ContextCompat.RECEIVER_NOT_EXPORTED); registeredInteractiveState = true; } } else { @@ -391,9 +402,9 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS watchdogIntent.setAction(ACTION_WATCHDOG); PendingIntent pi; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - pi = PendingIntent.getForegroundService(ServiceSinkhole.this, 1, watchdogIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + pi = PendingIntentCompat.getForegroundService(ServiceSinkhole.this, 1, watchdogIntent, PendingIntent.FLAG_UPDATE_CURRENT); else - pi = PendingIntent.getService(ServiceSinkhole.this, 1, watchdogIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + pi = PendingIntentCompat.getService(ServiceSinkhole.this, 1, watchdogIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.cancel(pi); @@ -1091,7 +1102,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS remoteViews.setTextViewText(R.id.tvMax, getString(R.string.msg_mbsec, max / 2 / 1000 / 1000)); // Show session/file count - if (filter && loglevel <= Log.WARN) { + if (BuildConfig.DEBUG) { int[] count = jni_get_stats(jni_context); remoteViews.setTextViewText(R.id.tvSessions, count[0] + "/" + count[1] + "/" + count[2]); remoteViews.setTextViewText(R.id.tvFiles, count[3] + "/" + count[4]); @@ -1102,7 +1113,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS // Show notification Intent main = new Intent(ServiceSinkhole.this, ActivityMain.class); - PendingIntent pi = PendingIntent.getActivity(ServiceSinkhole.this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(ServiceSinkhole.this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); @@ -1127,8 +1138,14 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS startForeground(NOTIFY_TRAFFIC, builder.build()); state = State.stats; Log.d(TAG, "Start foreground state=" + state.toString()); - } else - NotificationManagerCompat.from(ServiceSinkhole.this).notify(NOTIFY_TRAFFIC, builder.build()); + } else { + if (Util.canNotify(ServiceSinkhole.this)) + if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { + System.out.println("unable to get permission to post notificatoins.."); + return; + } + NotificationManagerCompat.from(ServiceSinkhole.this).notify(NOTIFY_TRAFFIC, builder.build()); + } } } @@ -1233,11 +1250,11 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS ParcelFileDescriptor pfd = builder.establish(); // Set underlying network - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && false) { ConnectivityManager cm = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE); Network active = (cm == null ? null : cm.getActiveNetwork()); if (active != null) { - Log.i(TAG, "Setting underlying network=" + cm.getNetworkInfo(active)); + Log.i(TAG, "Setting underlying network=" + active + " " + cm.getNetworkInfo(active)); setUnderlyingNetworks(new Network[]{active}); } } @@ -1286,6 +1303,20 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS } } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) + try { + ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + Network active = (cm == null ? null : cm.getActiveNetwork()); + LinkProperties props = (active == null ? null : cm.getLinkProperties(active)); + String domain = (props == null ? null : props.getDomains()); + if (domain != null) { + Log.i(TAG, "Using search domain=" + domain); + builder.addSearchDomain(domain); + } + } catch (Throwable ex) { + Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); + } + // Subnet routing if (subnet) { // Exclude IP ranges @@ -1395,6 +1426,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS Log.i(TAG, "Exclude " + exclude.getStart().getHostAddress() + "..." + exclude.getEnd().getHostAddress()); for (IPUtil.CIDR include : IPUtil.toCIDR(start, IPUtil.minus1(exclude.getStart()))) try { + System.out.println("adding vpn build route: " + include.address + ", prefix: " + include.prefix); builder.addRoute(include.address, include.prefix); } catch (Throwable ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); @@ -1425,19 +1457,31 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS // Add list of allowed applications if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - try { - builder.addDisallowedApplication(getPackageName()); - } catch (PackageManager.NameNotFoundException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - if (last_connected && !filter) + if (last_connected && !filter) { + Map mapDisallowed = new HashMap<>(); + for (Rule rule : listRule) + mapDisallowed.put(rule.packageName, rule); for (Rule rule : listAllowed) + mapDisallowed.remove(rule.packageName); + for (String packageName : mapDisallowed.keySet()) + try { + builder.addAllowedApplication(packageName); + Log.i(TAG, "Sinkhole " + packageName); + } catch (PackageManager.NameNotFoundException ex) { + Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); + } + if (mapDisallowed.size() == 0) try { - builder.addDisallowedApplication(rule.packageName); + builder.addAllowedApplication(getPackageName()); } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } - else if (filter) + } else if (filter) { + try { + builder.addDisallowedApplication(getPackageName()); + } catch (PackageManager.NameNotFoundException ex) { + Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); + } for (Rule rule : listRule) if (!rule.apply || (!system && rule.system)) try { @@ -1446,13 +1490,34 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS } catch (PackageManager.NameNotFoundException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } + } } // Build configure intent Intent configure = new Intent(this, ActivityMain.class); - PendingIntent pi = PendingIntent.getActivity(this, 0, configure, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(this, 0, configure, PendingIntent.FLAG_UPDATE_CURRENT); builder.setConfigureIntent(pi); + + List dlowed = builder.listDisallowed; + List as = builder.listAddress; + List rs = builder.listRoute; + + for (String d : dlowed) { + System.out.println("vpn builder skipping route over tun for package: " + d); + } + + System.out.println("\n\n"); + for (String a: as) { + System.out.println("vpn builder tun addr: " + a); + } + + System.out.println("\n\n"); + for (String r : rs) { + System.out.println("vpn builder routes: " + r); + } + + return builder; } @@ -1468,6 +1533,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS if (filter) { prepareUidAllowed(listAllowed, listRule); prepareHostsBlocked(); + prepareMalwareList(); prepareUidIPFilters(null); prepareForwarding(); } else { @@ -1475,6 +1541,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS mapUidAllowed.clear(); mapUidKnown.clear(); mapHostsBlocked.clear(); + mapMalware.clear(); mapUidIPFilters.clear(); mapForward.clear(); lock.writeLock().unlock(); @@ -1488,8 +1555,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS lock.writeLock().unlock(); } - //if (log || log_app || filter) { - if (true) { + if (log || log_app || filter) { int prio = Integer.parseInt(prefs.getString("loglevel", Integer.toString(Log.WARN))); final int rcode = Integer.parseInt(prefs.getString("rcode", "3")); if (prefs.getBoolean("socks5_enabled", false)) @@ -1553,6 +1619,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS mapUidAllowed.clear(); mapUidKnown.clear(); mapHostsBlocked.clear(); + mapMalware.clear(); mapUidIPFilters.clear(); mapForward.clear(); mapNotify.clear(); @@ -1615,7 +1682,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS Log.i(TAG, "Invalid hosts file line: " + line); } } - mapHostsBlocked.put("test.netguard.me", true); + mapHostsBlocked.put("test.networkgenie.me", true); Log.i(TAG, count + " hosts read"); } catch (IOException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); @@ -1631,6 +1698,63 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS lock.writeLock().unlock(); } + private void prepareMalwareList() { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSinkhole.this); + boolean malware = prefs.getBoolean("filter", false) && prefs.getBoolean("malware", false); + File file = new File(getFilesDir(), "malware.txt"); + if (!malware || !file.exists() || !file.canRead()) { + Log.i(TAG, "Malware use=" + malware + " exists=" + file.exists()); + lock.writeLock().lock(); + mapMalware.clear(); + lock.writeLock().unlock(); + return; + } + + boolean changed = (file.lastModified() != last_malware_modified); + if (!changed && mapMalware.size() > 0) { + Log.i(TAG, "Malware unchanged"); + return; + } + last_malware_modified = file.lastModified(); + + lock.writeLock().lock(); + + mapMalware.clear(); + + int count = 0; + BufferedReader br = null; + try { + br = new BufferedReader(new FileReader(file)); + String line; + while ((line = br.readLine()) != null) { + int hash = line.indexOf('#'); + if (hash >= 0) + line = line.substring(0, hash); + line = line.trim(); + if (line.length() > 0) { + String[] words = line.split("\\s+"); + if (words.length > 1) { + count++; + mapMalware.put(words[1], true); + } else + Log.i(TAG, "Invalid malware file line: " + line); + } + } + Log.i(TAG, count + " malware read"); + } catch (IOException ex) { + Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); + } finally { + if (br != null) + try { + br.close(); + } catch (IOException exex) { + Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex)); + } + } + + lock.writeLock().unlock(); + } + private void prepareUidIPFilters(String dname) { SharedPreferences lockdown = getSharedPreferences("lockdown", Context.MODE_PRIVATE); @@ -1645,15 +1769,15 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS } try (Cursor cursor = DatabaseHelper.getInstance(ServiceSinkhole.this).getAccessDns(dname)) { - int colUid = cursor.getColumnIndex("uid"); - int colVersion = cursor.getColumnIndex("version"); - int colProtocol = cursor.getColumnIndex("protocol"); - int colDAddr = cursor.getColumnIndex("daddr"); - int colResource = cursor.getColumnIndex("resource"); - int colDPort = cursor.getColumnIndex("dport"); - int colBlock = cursor.getColumnIndex("block"); - int colTime = cursor.getColumnIndex("time"); - int colTTL = cursor.getColumnIndex("ttl"); + int colUid = cursor.getColumnIndexOrThrow("uid"); + int colVersion = cursor.getColumnIndexOrThrow("version"); + int colProtocol = cursor.getColumnIndexOrThrow("protocol"); + int colDAddr = cursor.getColumnIndexOrThrow("daddr"); + int colResource = cursor.getColumnIndexOrThrow("resource"); + int colDPort = cursor.getColumnIndexOrThrow("dport"); + int colBlock = cursor.getColumnIndexOrThrow("block"); + int colTime = cursor.getColumnIndexOrThrow("time"); + int colTTL = cursor.getColumnIndexOrThrow("ttl"); while (cursor.moveToNext()) { int uid = cursor.getInt(colUid); int version = cursor.getInt(colVersion); @@ -1720,11 +1844,11 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (prefs.getBoolean("filter", false)) { try (Cursor cursor = DatabaseHelper.getInstance(ServiceSinkhole.this).getForwarding()) { - int colProtocol = cursor.getColumnIndex("protocol"); - int colDPort = cursor.getColumnIndex("dport"); - int colRAddr = cursor.getColumnIndex("raddr"); - int colRPort = cursor.getColumnIndex("rport"); - int colRUid = cursor.getColumnIndex("ruid"); + int colProtocol = cursor.getColumnIndexOrThrow("protocol"); + int colDPort = cursor.getColumnIndexOrThrow("dport"); + int colRAddr = cursor.getColumnIndexOrThrow("raddr"); + int colRPort = cursor.getColumnIndexOrThrow("rport"); + int colRUid = cursor.getColumnIndexOrThrow("ruid"); while (cursor.moveToNext()) { Forward fwd = new Forward(); fwd.protocol = cursor.getInt(colProtocol); @@ -1882,6 +2006,20 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS Log.i(TAG, "New IP " + rr); prepareUidIPFilters(rr.QName); } + if (rr.uid > 0 && !TextUtils.isEmpty(rr.AName)) { + lock.readLock().lock(); + boolean malware = (mapMalware.containsKey(rr.AName) && mapMalware.get(rr.AName)); + lock.readLock().unlock(); + + if (malware) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + boolean notified = prefs.getBoolean("malware." + rr.uid, false); + if (!notified) { + prefs.edit().putBoolean("malware." + rr.uid, true).apply(); + notifyNewApplication(rr.uid, true); + } + } + } } // Called from native code @@ -1921,86 +2059,138 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS // Called from native code private Allowed getRomAction(Packet packet) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - lock.readLock().lock(); - System.out.println("BPB: check if allowed packet with source: " + packet.saddr + ":" + packet.sport + " -> " + packet.daddr + ":" + packet.dport); + packet.allowed = true; // flip this to false to block all traffic - packet.allowed = false; - if (prefs.getBoolean("filter", false)) { - // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h - if (packet.protocol == 17 /* UDP */ && !prefs.getBoolean("filter_udp", false)) { - // Allow unfiltered UDP - packet.allowed = true; - Log.i(TAG, "Allowing UDP " + packet); - } else if (packet.uid < 2000 && - !last_connected && isSupported(packet.protocol) && false) { - // Allow system applications in disconnected state - packet.allowed = true; - Log.w(TAG, "Allowing disconnected system " + packet); - } else if (packet.uid < 2000 && - !mapUidKnown.containsKey(packet.uid) && isSupported(packet.protocol)) { - // Allow unknown system traffic - packet.allowed = true; - Log.w(TAG, "Allowing unknown system " + packet); - } else if (packet.uid == Process.myUid()) { - // Allow self - packet.allowed = true; - Log.w(TAG, "Allowing self " + packet); - } else { - boolean filtered = false; - IPKey key = new IPKey(packet.version, packet.protocol, packet.dport, packet.uid); - if (mapUidIPFilters.containsKey(key)) - try { - InetAddress iaddr = InetAddress.getByName(packet.daddr); - Map map = mapUidIPFilters.get(key); - if (map != null && map.containsKey(iaddr)) { - IPRule rule = map.get(iaddr); - if (rule.isExpired()) - Log.i(TAG, "DNS expired " + packet + " rule " + rule); - else { - filtered = true; - packet.allowed = !rule.isBlocked(); - Log.i(TAG, "Filtering " + packet + - " allowed=" + packet.allowed + " rule " + rule); - } - } - } catch (UnknownHostException ex) { - Log.w(TAG, "Allowed " + ex.toString() + "\n" + Log.getStackTraceString(ex)); - } + // Read in ROM and decide the action to return to C function + String romInfo = readRom(); + System.out.println("rom info: " + romInfo + ", current send info: " + sendType + ", send conn: " + sendConn); - if (!filtered) - if (mapUidAllowed.containsKey(packet.uid)) - packet.allowed = mapUidAllowed.get(packet.uid); - else - Log.w(TAG, "No rules for " + packet); + // Next: based on this romInfo we read in, decide + // the action for this packet that will be returned below + + String extraInfo = "time: " + packet.time + ", uid: " + packet.uid + ", protocol: " + packet.protocol + ", flags" + packet.flags + ", data: " + packet.data; + String packetInfo = "packet from " + packet.saddr + ":" + packet.sport + " to " + packet.daddr + ":" + packet.dport; + genieInfo = packetInfo + "\n\n " + extraInfo; + lock.readLock().unlock(); + + for (Integer suid : mapUidKnown.keySet()) { + if (packet.uid == suid) { + System.out.println("known pkt with uid: " + packet.uid); + } + } + for (Integer suid : mapUidAllowed.keySet()) { + if (packet.uid == suid) { + System.out.println("alowed pkt with uid: " + packet.uid); } } - Allowed allowed = null; - if (packet.allowed) { - if (mapForward.containsKey(packet.dport)) { - Forward fwd = mapForward.get(packet.dport); - if (fwd.ruid == packet.uid) { - allowed = new Allowed(); - } else { - allowed = new Allowed(fwd.raddr, fwd.rport); - packet.data = "> " + fwd.raddr + "/" + fwd.rport; - } - } else - allowed = new Allowed(); + Allowed allowed = new Allowed(); + allowed.bypass = 2; // right now 1 = enable ack bypass, 2+ = normal allowed, 0 = drop packets (not allowed), 3 = special, 5 = rst + + if (sendType.equals("sendo")) { + System.out.println("marking special send packet"); + sendType = "none"; + allowed.bypass = 3; + } else if (sendType.equals("reset")) { + sendType = "none"; + allowed.bypass = 5; + } else if (sendType.equals("ping")) { + sendType = "none"; + allowed.bypass = 7; + } else if (sendType.equals("udp")) { + allowed.bypass = 9; + sendType = "none"; + } else if (sendType.equals("push")) { + sendType = "none"; + allowed.bypass = 10; } - lock.readLock().unlock(); - if (prefs.getBoolean("log", false) || prefs.getBoolean("log_app", false)) - if (packet.protocol != 6 /* TCP */ || !"".equals(packet.flags)) - if (packet.uid != Process.myUid()) - logPacket(packet); + if (packet.daddr.equals(currGenieDestIp) && packet.protocol == 6) { // if outgoing packet is to test server and UDP + System.out.println("Setting the curr test TCP conn info for GUI: " + packetInfo); + String cinfo = packet.saddr + ">" + packet.sport + ">" + packet.daddr + ">" + packet.dport; + currConnInfo = cinfo; + } + + if (packet.daddr.equals(currGenieDestIp) && packet.protocol == 17) { // if outgoing packet is to test server and UDP + System.out.println("Setting the curr test UDP conn info for GUI: " + packetInfo); + String cinfo = packet.saddr + ">" + packet.sport + ">" + packet.daddr + ">" + packet.dport; + currConnInfo = cinfo; + } + + int dport = packet.dport; + if (dport == 53 || dport == 443 || dport == 80) { + genieLogPktInfo(packet); + } + allowed.sender = sendConn; + System.out.println("Genie handling sink pkt with daddr: " + packet.daddr + ", current genie dest: " + currGenieDestIp); + System.out.println("return some allowed object: " + allowed.toString() + " for packet: " + packet); return allowed; } + public static String getLastInfo() { + return genieInfo; + } + + public static String getLastConnInfo() { + return currConnInfo; + } + + public static void updateCurrTestIp(String tconnInfo) { + String[] sparts = tconnInfo.split(">"); + int slen = sparts.length; + + if (slen > 1) { + String newTargIp = sparts[1]; + currGenieDestIp = newTargIp; + System.out.println("Updating current test conn ip to: " + newTargIp + " from " + tconnInfo); + } + + + printDebugGenieInfo(); + } + + public static int setSender(String sinfo, String testConn) { + sendType = sinfo; + sendConn = testConn; + updateCurrTestIp(testConn); + + return 1; + } + + + public static void printDebugGenieInfo() { + System.out.println("GEE VPN sinkhole >> genie dest ip: " + currGenieDestIp + ", send type: " + sendType + ", send conn: " + sendConn + ", conn info: " + currConnInfo); + } + + private String readRom() + { + return "blahh"; + } + + private void genieLogPktInfo(Packet packet) { + + int dport = packet.dport; + int sport = packet.sport; + String ptype = "using something"; + if (dport == 80) { + ptype = "cleartext HTTP"; + } else if(dport == 443) { + ptype = "HTTPS"; + } else if(dport == 53) { + ptype = "DNS reply"; + } else if(sport == 53) { + ptype = "DNS response"; + } + DatabaseHelper dh = DatabaseHelper.getInstance(this); + String dname = dh.getQName(packet.uid, packet.daddr); + String cinfo = packet.saddr + ">" + sport + ">" + packet.daddr + ">" + dport + " TO: " + dname; + System.out.println("Genie found a packet " + ptype + ": " + cinfo + " from uid: " + packet.uid); + } + // Called from native code private void accountUsage(Usage usage) { logHandler.account(usage); @@ -2018,7 +2208,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(ACTION_SCREEN_OFF_DELAYED); i.setPackage(context.getPackageName()); - PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); am.cancel(pi); try { @@ -2122,7 +2312,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS }; ConnectivityManager.NetworkCallback networkMonitorCallback = new ConnectivityManager.NetworkCallback() { - private String TAG = "NetGuard.Monitor"; + private String TAG = "Networkgenie.Monitor"; private Map validated = new HashMap<>(); @@ -2171,7 +2361,8 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS } private void checkConnectivity(Network network, NetworkInfo ni, NetworkCapabilities capabilities) { - if (ni != null && capabilities != null && + if (isActiveNetwork(network) && + ni != null && capabilities != null && ni.getDetailedState() != NetworkInfo.DetailedState.SUSPENDED && ni.getDetailedState() != NetworkInfo.DetailedState.BLOCKED && ni.getDetailedState() != NetworkInfo.DetailedState.DISCONNECTED && @@ -2257,7 +2448,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (IAB.isPurchased(ActivityPro.SKU_NOTIFY, context) && prefs.getBoolean("install", true)) { int uid = intent.getIntExtra(Intent.EXTRA_UID, -1); - notifyNewApplication(uid); + notifyNewApplication(uid, false); } } @@ -2299,14 +2490,19 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS } }; - public void notifyNewApplication(int uid) { + public void notifyNewApplication(int uid, boolean malware) { if (uid < 0) return; + if (uid == Process.myUid()) + return; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); try { // Get application name - String name = TextUtils.join(", ", Util.getApplicationNames(uid, this)); + List names = Util.getApplicationNames(uid, this); + if (names.size() == 0) + return; + String name = TextUtils.join(", ", names); // Get application info PackageManager pm = getPackageManager(); @@ -2319,22 +2515,28 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS Intent main = new Intent(this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_REFRESH, true); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); - PendingIntent pi = PendingIntent.getActivity(this, uid, main, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(this, uid, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); - NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "notify"); + NotificationCompat.Builder builder = new NotificationCompat.Builder(this, + malware ? "malware" : "notify"); builder.setSmallIcon(R.drawable.ic_security_white_24dp) .setContentIntent(pi) .setColor(tv.data) .setAutoCancel(true); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + if (malware) builder.setContentTitle(name) - .setContentText(getString(R.string.msg_installed_n)); - else - builder.setContentTitle(getString(R.string.app_name)) - .setContentText(getString(R.string.msg_installed, name)); + .setContentText(getString(R.string.msg_malware, name)); + else { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + builder.setContentTitle(name) + .setContentText(getString(R.string.msg_installed_n)); + else + builder.setContentTitle(getString(R.string.app_name)) + .setContentText(getString(R.string.msg_installed, name)); + } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) builder.setCategory(NotificationCompat.CATEGORY_STATUS) @@ -2354,7 +2556,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS riWifi.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riWifi.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !wifi); - PendingIntent piWifi = PendingIntent.getService(this, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent piWifi = PendingIntentCompat.getService(this, uid, riWifi, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action wAction = new NotificationCompat.Action.Builder( wifi ? R.drawable.wifi_on : R.drawable.wifi_off, getString(wifi ? R.string.title_allow_wifi : R.string.title_block_wifi), @@ -2369,7 +2571,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS riOther.putExtra(ServiceSinkhole.EXTRA_UID, uid); riOther.putExtra(ServiceSinkhole.EXTRA_PACKAGE, packages[0]); riOther.putExtra(ServiceSinkhole.EXTRA_BLOCKED, !other); - PendingIntent piOther = PendingIntent.getService(this, uid + 10000, riOther, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent piOther = PendingIntentCompat.getService(this, uid + 10000, riOther, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Action oAction = new NotificationCompat.Action.Builder( other ? R.drawable.other_on : R.drawable.other_off, getString(other ? R.string.title_allow_other : R.string.title_block_other), @@ -2378,16 +2580,22 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS builder.addAction(oAction); // Show notification - if (internet) - NotificationManagerCompat.from(this).notify(uid, builder.build()); - else { + if (internet) { + if (Util.canNotify(this)) + if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { + System.out.println("unable to get permission to post notificatoins.."); + return; + } + NotificationManagerCompat.from(this).notify(uid, builder.build()); + } else { NotificationCompat.BigTextStyle expanded = new NotificationCompat.BigTextStyle(builder); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) expanded.bigText(getString(R.string.msg_installed_n)); else expanded.bigText(getString(R.string.msg_installed, name)); expanded.setSummaryText(getString(R.string.title_internet)); - NotificationManagerCompat.from(this).notify(uid, expanded.build()); + if (Util.canNotify(this)) + NotificationManagerCompat.from(this).notify(uid, expanded.build()); } } catch (PackageManager.NameNotFoundException ex) { @@ -2442,7 +2650,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS IntentFilter ifUser = new IntentFilter(); ifUser.addAction(Intent.ACTION_USER_BACKGROUND); ifUser.addAction(Intent.ACTION_USER_FOREGROUND); - registerReceiver(userReceiver, ifUser); + ContextCompat.registerReceiver(this, userReceiver, ifUser, ContextCompat.RECEIVER_NOT_EXPORTED); registeredUser = true; } @@ -2450,7 +2658,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { IntentFilter ifIdle = new IntentFilter(); ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED); - registerReceiver(idleStateReceiver, ifIdle); + ContextCompat.registerReceiver(this, idleStateReceiver, ifIdle, ContextCompat.RECEIVER_NOT_EXPORTED); registeredIdleState = true; } @@ -2459,7 +2667,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED); ifPackage.addAction(Intent.ACTION_PACKAGE_REMOVED); ifPackage.addDataScheme("package"); - registerReceiver(packageChangedReceiver, ifPackage); + ContextCompat.registerReceiver(this, packageChangedReceiver, ifPackage, ContextCompat.RECEIVER_NOT_EXPORTED); registeredPackageChanged = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) @@ -2484,9 +2692,9 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS alarmIntent.setAction(ACTION_HOUSE_HOLDING); PendingIntent pi; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - pi = PendingIntent.getForegroundService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + pi = PendingIntentCompat.getForegroundService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); else - pi = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + pi = PendingIntentCompat.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000, AlarmManager.INTERVAL_HALF_DAY, pi); @@ -2502,21 +2710,30 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS builder.addCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED); ConnectivityManager.NetworkCallback nc = new ConnectivityManager.NetworkCallback() { + private Network last_active = null; + private Network last_network = null; private Boolean last_connected = null; - private Boolean last_unmetered = null; + private Boolean last_metered = null; private String last_generation = null; private List last_dns = null; @Override public void onAvailable(Network network) { Log.i(TAG, "Available network=" + network); + if (!isActiveNetwork(network)) + return; + + last_active = network; last_connected = Util.isConnected(ServiceSinkhole.this); + last_metered = Util.isMeteredNetwork(ServiceSinkhole.this); reload("network available", ServiceSinkhole.this, false); } @Override public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) { Log.i(TAG, "Changed properties=" + network + " props=" + linkProperties); + if (!isActiveNetwork(network)) + return; // Make sure the right DNS servers are being used List dns = linkProperties.getDnsServers(); @@ -2535,36 +2752,51 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS @Override public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) { Log.i(TAG, "Changed capabilities=" + network + " caps=" + networkCapabilities); + if (!isActiveNetwork(network)) + return; boolean connected = Util.isConnected(ServiceSinkhole.this); - boolean unmetered = networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED); + boolean metered = Util.isMeteredNetwork(ServiceSinkhole.this); String generation = Util.getNetworkGeneration(ServiceSinkhole.this); Log.i(TAG, "Connected=" + connected + "/" + last_connected + - " unmetered=" + unmetered + "/" + last_unmetered + + " unmetered=" + metered + "/" + last_metered + " generation=" + generation + "/" + last_generation); - if (last_connected != null && !last_connected.equals(connected)) - reload("Connected state changed", ServiceSinkhole.this, false); + String reason = null; + + if (reason == null && !Objects.equals(network, last_network)) + reason = "Network changed"; + + if (reason == null && last_connected != null && !last_connected.equals(connected)) + reason = "Connected state changed"; - if (last_unmetered != null && !last_unmetered.equals(unmetered)) - reload("Unmetered state changed", ServiceSinkhole.this, false); + if (reason == null && last_metered != null && !last_metered.equals(metered)) + reason = "Unmetered state changed"; - if (last_generation != null && !last_generation.equals(generation)) { + if (reason == null && last_generation != null && !last_generation.equals(generation)) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSinkhole.this); if (prefs.getBoolean("unmetered_2g", false) || prefs.getBoolean("unmetered_3g", false) || prefs.getBoolean("unmetered_4g", false)) - reload("Generation changed", ServiceSinkhole.this, false); + reason = "Generation changed"; } + if (reason != null) + reload(reason, ServiceSinkhole.this, false); + + last_network = network; last_connected = connected; - last_unmetered = unmetered; + last_metered = metered; last_generation = generation; } @Override public void onLost(Network network) { - Log.i(TAG, "Lost network=" + network); + Log.i(TAG, "Lost network=" + network + " active=" + isActiveNetwork(network)); + if (last_active == null || !last_active.equals(network)) + return; + + last_active = null; last_connected = Util.isConnected(ServiceSinkhole.this); reload("network lost", ServiceSinkhole.this, false); } @@ -2591,7 +2823,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS Log.i(TAG, "Starting listening to connectivity changes"); IntentFilter ifConnectivity = new IntentFilter(); ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION); - registerReceiver(connectivityChangedReceiver, ifConnectivity); + ContextCompat.registerReceiver(this, connectivityChangedReceiver, ifConnectivity, ContextCompat.RECEIVER_NOT_EXPORTED); registeredConnectivityChanged = true; // Listen for phone state changes @@ -2603,6 +2835,55 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS } } + private Network getActiveNetwork() { + ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + if (cm == null) + return null; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + Network active = cm.getActiveNetwork(); + if (active == null) { + Log.i(TAG, "getActiveNetwork: no active network"); + return null; + } + + NetworkCapabilities caps = cm.getNetworkCapabilities(active); + if (caps != null && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) + return active; + else + Log.w(TAG, "getActiveNetwork: active network is VPN"); + + } + + NetworkInfo ani = cm.getActiveNetworkInfo(); + if (ani == null) + return null; + + Network[] networks = cm.getAllNetworks(); + for (Network network : networks) { + NetworkCapabilities caps = cm.getNetworkCapabilities(network); + Log.i(TAG, "getActiveNetwork: network=" + network + " caps=" + caps); + if (caps == null || !caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)) + continue; + + NetworkInfo ni = cm.getNetworkInfo(network); + if (ni == null) + continue; + if (ni.getType() == ani.getType() && + ni.getSubtype() == ani.getSubtype()) { + Log.i(TAG, "getActiveNetwork: returning network=" + network); + return network; + } + } + + Log.i(TAG, "getActiveNetwork: no active network found"); + return null; + } + + private boolean isActiveNetwork(Network network) { + return (network != null && network.equals(getActiveNetwork())); + } + @Override public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { if ("theme".equals(name)) { @@ -2694,7 +2975,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS ServiceSinkhole.reload("notification", ServiceSinkhole.this, false); // Update notification - notifyNewApplication(uid); + notifyNewApplication(uid, false); // Update UI Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED); @@ -2803,7 +3084,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS private Notification getEnforcingNotification(int allowed, int blocked, int hosts) { Intent main = new Intent(this, ActivityMain.class); - PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); @@ -2862,12 +3143,13 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS // Update notification Notification notification = getEnforcingNotification(allowed, total - allowed, mapHostsBlocked.size()); NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - nm.notify(NOTIFY_ENFORCING, notification); + if (Util.canNotify(this)) + nm.notify(NOTIFY_ENFORCING, notification); } private Notification getWaitingNotification() { Intent main = new Intent(this, ActivityMain.class); - PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); @@ -2894,7 +3176,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS private void showDisabledNotification() { Intent main = new Intent(this, ActivityMain.class); - PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOff, tv, true); @@ -2914,12 +3196,17 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); notification.bigText(getString(R.string.msg_revoked)); - NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build()); + if (Util.canNotify(this)) + if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { + System.out.println("unable to get permission to post notificatoins.."); + return; + } + NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build()); } private void showLockdownNotification() { Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS); - PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_LOCKDOWN, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(this, NOTIFY_LOCKDOWN, intent, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOff, tv, true); @@ -2940,7 +3227,12 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); notification.bigText(getString(R.string.msg_always_on_lockdown)); - NotificationManagerCompat.from(this).notify(NOTIFY_LOCKDOWN, notification.build()); + if (Util.canNotify(this)) + if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { + System.out.println("unable to get permission to post notificatoins.."); + return; + } + NotificationManagerCompat.from(this).notify(NOTIFY_LOCKDOWN, notification.build()); } private void removeLockdownNotification() { @@ -2950,7 +3242,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS private void showAutoStartNotification() { Intent main = new Intent(this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_APPROVE, true); - PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_AUTOSTART, main, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(this, NOTIFY_AUTOSTART, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOff, tv, true); @@ -2970,12 +3262,17 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder); notification.bigText(getString(R.string.msg_autostart)); - NotificationManagerCompat.from(this).notify(NOTIFY_AUTOSTART, notification.build()); + if (Util.canNotify(this)) + if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { + System.out.println("unable to get permission to post notificatoins.."); + return; + } + NotificationManagerCompat.from(this).notify(NOTIFY_AUTOSTART, notification.build()); } private void showErrorNotification(String message) { Intent main = new Intent(this, ActivityMain.class); - PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOff, tv, true); @@ -2996,15 +3293,23 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS notification.bigText(getString(R.string.msg_error, message)); notification.setSummaryText(message); - NotificationManagerCompat.from(this).notify(NOTIFY_ERROR, notification.build()); + if (Util.canNotify(this)) + if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { + System.out.println("unable to get permission to post notificatoins.."); + return; + } + NotificationManagerCompat.from(this).notify(NOTIFY_ERROR, notification.build()); } private void showAccessNotification(int uid) { - String name = TextUtils.join(", ", Util.getApplicationNames(uid, ServiceSinkhole.this)); + List apps = Util.getApplicationNames(uid, ServiceSinkhole.this); + if (apps.size() == 0) + return; + String name = TextUtils.join(", ", apps); Intent main = new Intent(ServiceSinkhole.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); - PendingIntent pi = PendingIntent.getActivity(ServiceSinkhole.this, uid + 10000, main, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(ServiceSinkhole.this, uid + 10000, main, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorOn, tv, true); @@ -3054,9 +3359,9 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS } try (Cursor cursor = DatabaseHelper.getInstance(ServiceSinkhole.this).getAccessUnset(uid, 7, since)) { - int colDAddr = cursor.getColumnIndex("daddr"); - int colTime = cursor.getColumnIndex("time"); - int colAllowed = cursor.getColumnIndex("allowed"); + int colDAddr = cursor.getColumnIndexOrThrow("daddr"); + int colTime = cursor.getColumnIndexOrThrow("time"); + int colAllowed = cursor.getColumnIndexOrThrow("allowed"); while (cursor.moveToNext()) { StringBuilder sb = new StringBuilder(); sb.append(df.format(cursor.getLong(colTime))).append(' '); @@ -3081,12 +3386,17 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS } } - NotificationManagerCompat.from(this).notify(uid + 10000, notification.build()); + if (Util.canNotify(this)) + if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { + System.out.println("unable to get permission to post notificatoins.."); + return; + } + NotificationManagerCompat.from(this).notify(uid + 10000, notification.build()); } private void showUpdateNotification(String name, String url) { Intent download = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - PendingIntent pi = PendingIntent.getActivity(this, 0, download, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getActivity(this, 0, download, PendingIntent.FLAG_UPDATE_CURRENT); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); @@ -3103,7 +3413,12 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS builder.setCategory(NotificationCompat.CATEGORY_STATUS) .setVisibility(NotificationCompat.VISIBILITY_SECRET); - NotificationManagerCompat.from(this).notify(NOTIFY_UPDATE, builder.build()); + if (Util.canNotify(this)) + if (ActivityCompat.checkSelfPermission(ServiceSinkhole.this, android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { + System.out.println("unable to get permission to post notificatoins.."); + return; + } + NotificationManagerCompat.from(this).notify(NOTIFY_UPDATE, builder.build()); } private void removeWarningNotifications() { @@ -3113,16 +3428,19 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS } private class Builder extends VpnService.Builder { + private Network activeNetwork; private NetworkInfo networkInfo; private int mtu; private List listAddress = new ArrayList<>(); private List listRoute = new ArrayList<>(); private List listDns = new ArrayList<>(); + private List listAllowed = new ArrayList<>(); private List listDisallowed = new ArrayList<>(); private Builder() { super(); ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); + activeNetwork = (Build.VERSION.SDK_INT < Build.VERSION_CODES.M ? null : cm.getActiveNetwork()); networkInfo = cm.getActiveNetworkInfo(); } @@ -3142,7 +3460,6 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS @Override public Builder addRoute(String address, int prefixLength) { - System.out.println("BPB: adding new route: " + address + "/" + prefixLength); listRoute.add(address + "/" + prefixLength); super.addRoute(address, prefixLength); return this; @@ -3162,6 +3479,12 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS return this; } + @Override + public VpnService.Builder addAllowedApplication(String packageName) throws PackageManager.NameNotFoundException { + listAllowed.add(packageName); + return super.addAllowedApplication(packageName); + } + @Override public Builder addDisallowedApplication(String packageName) throws PackageManager.NameNotFoundException { listDisallowed.add(packageName); @@ -3176,6 +3499,9 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS if (other == null) return false; + if (!Objects.equals(this.activeNetwork, other.activeNetwork)) + return false; + if (this.networkInfo == null || other.networkInfo == null || this.networkInfo.getType() != other.networkInfo.getType()) return false; @@ -3192,6 +3518,9 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS if (this.listDns.size() != other.listDns.size()) return false; + if (this.listAllowed.size() != other.listAllowed.size()) + return false; + if (this.listDisallowed.size() != other.listDisallowed.size()) return false; @@ -3207,6 +3536,10 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS if (!other.listDns.contains(dns)) return false; + for (String pkg : this.listAllowed) + if (!other.listAllowed.contains(pkg)) + return false; + for (String pkg : this.listDisallowed) if (!other.listDisallowed.contains(pkg)) return false; @@ -3297,14 +3630,34 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS Intent intent = new Intent(context, ServiceSinkhole.class); intent.putExtra(EXTRA_COMMAND, Command.run); intent.putExtra(EXTRA_REASON, reason); - ContextCompat.startForegroundService(context, intent); + try { + ContextCompat.startForegroundService(context, intent); + } catch (Throwable ex) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && + ex instanceof ForegroundServiceStartNotAllowedException) + try { + context.startService(intent); + } catch (Throwable exex) { + Log.e(TAG, exex + "\n" + Log.getStackTraceString(exex)); + } + } } public static void start(String reason, Context context) { Intent intent = new Intent(context, ServiceSinkhole.class); intent.putExtra(EXTRA_COMMAND, Command.start); intent.putExtra(EXTRA_REASON, reason); - ContextCompat.startForegroundService(context, intent); + try { + ContextCompat.startForegroundService(context, intent); + } catch (Throwable ex) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && + ex instanceof ForegroundServiceStartNotAllowedException) + try { + context.startService(intent); + } catch (Throwable exex) { + Log.e(TAG, exex + "\n" + Log.getStackTraceString(exex)); + } + } } public static void reload(String reason, Context context, boolean interactive) { @@ -3314,7 +3667,17 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS intent.putExtra(EXTRA_COMMAND, Command.reload); intent.putExtra(EXTRA_REASON, reason); intent.putExtra(EXTRA_INTERACTIVE, interactive); - ContextCompat.startForegroundService(context, intent); + try { + ContextCompat.startForegroundService(context, intent); + } catch (Throwable ex) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && + ex instanceof ForegroundServiceStartNotAllowedException) + try { + context.startService(intent); + } catch (Throwable exex) { + Log.e(TAG, exex + "\n" + Log.getStackTraceString(exex)); + } + } } } @@ -3323,13 +3686,33 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS intent.putExtra(EXTRA_COMMAND, Command.stop); intent.putExtra(EXTRA_REASON, reason); intent.putExtra(EXTRA_TEMPORARY, vpnonly); - ContextCompat.startForegroundService(context, intent); + try { + ContextCompat.startForegroundService(context, intent); + } catch (Throwable ex) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && + ex instanceof ForegroundServiceStartNotAllowedException) + try { + context.startService(intent); + } catch (Throwable exex) { + Log.e(TAG, exex + "\n" + Log.getStackTraceString(exex)); + } + } } public static void reloadStats(String reason, Context context) { Intent intent = new Intent(context, ServiceSinkhole.class); intent.putExtra(EXTRA_COMMAND, Command.stats); intent.putExtra(EXTRA_REASON, reason); - ContextCompat.startForegroundService(context, intent); + try { + ContextCompat.startForegroundService(context, intent); + } catch (Throwable ex) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && + ex instanceof ForegroundServiceStartNotAllowedException) + try { + context.startService(intent); + } catch (Throwable exex) { + Log.e(TAG, exex + "\n" + Log.getStackTraceString(exex)); + } + } } } diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileFilter.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileFilter.java similarity index 86% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileFilter.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileFilter.java index 3ffd0d4..85d0bcf 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileFilter.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileFilter.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ @@ -33,7 +33,7 @@ import androidx.preference.PreferenceManager; @TargetApi(Build.VERSION_CODES.N) public class ServiceTileFilter extends TileService implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.TileFilter"; + private static final String TAG = "Networkgenie.TileFilter"; public void onStartListening() { Log.i(TAG, "Start listening"); diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileGraph.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileGraph.java similarity index 86% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileGraph.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileGraph.java index 30c38ca..0254376 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileGraph.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileGraph.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ @@ -33,7 +33,7 @@ import androidx.preference.PreferenceManager; @TargetApi(Build.VERSION_CODES.N) public class ServiceTileGraph extends TileService implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.TileGraph"; + private static final String TAG = "Networkgenie.TileGraph"; public void onStartListening() { Log.i(TAG, "Start listening"); diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileLockdown.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileLockdown.java similarity index 85% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileLockdown.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileLockdown.java index 1aaffea..22a3974 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileLockdown.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileLockdown.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ @@ -32,7 +32,7 @@ import androidx.preference.PreferenceManager; @TargetApi(Build.VERSION_CODES.N) public class ServiceTileLockdown extends TileService implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.TileLockdown"; + private static final String TAG = "Networkgenie.TileLockdown"; public void onStartListening() { Log.i(TAG, "Start listening"); diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileMain.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileMain.java similarity index 86% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileMain.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileMain.java index 655819f..2591d62 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileMain.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/ServiceTileMain.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ @@ -38,7 +38,7 @@ import java.util.Date; @TargetApi(Build.VERSION_CODES.N) public class ServiceTileMain extends TileService implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.TileMain"; + private static final String TAG = "Networkgenie.TileMain"; public void onStartListening() { Log.i(TAG, "Start listening"); @@ -77,7 +77,7 @@ public class ServiceTileMain extends TileService implements SharedPreferences.On AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(WidgetAdmin.INTENT_ON); intent.setPackage(getPackageName()); - PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); am.cancel(pi); // Check state diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/SwitchPreference.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/SwitchPreference.java similarity index 74% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/SwitchPreference.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/SwitchPreference.java index c8192c6..8e74ef5 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/SwitchPreference.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/SwitchPreference.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.content.Context; diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Usage.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Usage.java similarity index 76% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Usage.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Usage.java index ccfcb7e..981c852 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Usage.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Usage.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import java.text.DateFormat; diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Util.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Util.java similarity index 75% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/Util.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Util.java index 1cae9fb..02bb85c 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Util.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Util.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.Manifest; @@ -39,13 +39,9 @@ import android.net.ConnectivityManager; import android.net.LinkProperties; import android.net.Network; import android.net.NetworkInfo; -import android.net.Uri; -import android.net.VpnService; import android.net.wifi.WifiManager; -import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; -import android.os.Debug; import android.os.PowerManager; import android.provider.Settings; import android.telephony.TelephonyManager; @@ -57,15 +53,13 @@ import android.view.View; import android.widget.TextView; import androidx.appcompat.app.AlertDialog; +import androidx.core.app.ActivityCompat; import androidx.core.net.ConnectivityManagerCompat; import androidx.preference.PreferenceManager; import java.io.BufferedReader; import java.io.File; -import java.io.FileReader; -import java.io.IOException; import java.io.InputStreamReader; -import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.io.UnsupportedEncodingException; @@ -77,7 +71,6 @@ import java.net.URL; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.text.DateFormat; -import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; @@ -89,7 +82,7 @@ import java.util.Map; import java.util.Set; public class Util { - private static final String TAG = "NetGuard.Util"; + private static final String TAG = "Networkgenie.Util"; // Roam like at home private static final List listEU = Arrays.asList( @@ -118,7 +111,6 @@ public class Util { "NO", // Norway "PL", // Poland "PT", // Portugal - "RE", // La Réunion "RO", // Romania "SK", // Slovakia "SI", // Slovenia @@ -134,7 +126,7 @@ public class Util { static { try { - System.loadLibrary("netguard"); + System.loadLibrary("networkgenie"); } catch (UnsatisfiedLinkError ignored) { System.exit(1); } @@ -413,13 +405,13 @@ public class Util { else { PackageManager pm = context.getPackageManager(); String[] pkgs = pm.getPackagesForUid(uid); - if (pkgs == null) - listResult.add(Integer.toString(uid)); - else + if (pkgs != null) for (String pkg : pkgs) try { ApplicationInfo info = pm.getApplicationInfo(pkg, 0); - listResult.add(pm.getApplicationLabel(info).toString()); + String name = pm.getApplicationLabel(info).toString(); + if (!TextUtils.isEmpty(name)) + listResult.add(name); } catch (PackageManager.NameNotFoundException ignored) { } Collections.sort(listResult); @@ -756,20 +748,20 @@ public class Util { /* 06-14 13:02:41.331 19703 19703 W ircode.netguar: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) 06-14 13:02:41.332 19703 19703 W ircode.netguar: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) - 06-14 13:02:41.495 19703 19703 I TetheringManager: registerTetheringEventCallback:eu.faircode.netguard - 06-14 13:02:41.518 19703 19703 E AndroidRuntime: Process: eu.faircode.netguard, PID: 19703 - 06-14 13:02:41.518 19703 19703 E AndroidRuntime: at eu.faircode.netguard.Util.getGeneralInfo(SourceFile:744) - 06-14 13:02:41.518 19703 19703 E AndroidRuntime: at eu.faircode.netguard.ActivitySettings.updateTechnicalInfo(SourceFile:858) - 06-14 13:02:41.518 19703 19703 E AndroidRuntime: at eu.faircode.netguard.ActivitySettings.onPostCreate(SourceFile:425) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: java.lang.SecurityException: getDataNetworkTypeForSubscriber - 06-14 13:02:41.520 19703 19703 W NetGuard.App: java.lang.SecurityException: getDataNetworkTypeForSubscriber - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.os.Parcel.createExceptionOrNull(Parcel.java:2373) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.os.Parcel.createException(Parcel.java:2357) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.os.Parcel.readException(Parcel.java:2340) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.os.Parcel.readException(Parcel.java:2282) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at com.android.internal.telephony.ITelephony$Stub$Proxy.getNetworkTypeForSubscriber(ITelephony.java:8711) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2945) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2909) + 06-14 13:02:41.495 19703 19703 I TetheringManager: registerTetheringEventCallback:com.breakpointingbad.networkgenie + 06-14 13:02:41.518 19703 19703 E AndroidRuntime: Process: com.breakpointingbad.networkgenie, PID: 19703 + 06-14 13:02:41.518 19703 19703 E AndroidRuntime: at com.breakpointingbad.networkgenie.Util.getGeneralInfo(SourceFile:744) + 06-14 13:02:41.518 19703 19703 E AndroidRuntime: at com.breakpointingbad.networkgenie.ActivitySettings.updateTechnicalInfo(SourceFile:858) + 06-14 13:02:41.518 19703 19703 E AndroidRuntime: at com.breakpointingbad.networkgenie.ActivitySettings.onPostCreate(SourceFile:425) + 06-14 13:02:41.520 19703 19703 W Networkgenie.App: java.lang.SecurityException: getDataNetworkTypeForSubscriber + 06-14 13:02:41.520 19703 19703 W Networkgenie.App: java.lang.SecurityException: getDataNetworkTypeForSubscriber + 06-14 13:02:41.520 19703 19703 W Networkgenie.App: at android.os.Parcel.createExceptionOrNull(Parcel.java:2373) + 06-14 13:02:41.520 19703 19703 W Networkgenie.App: at android.os.Parcel.createException(Parcel.java:2357) + 06-14 13:02:41.520 19703 19703 W Networkgenie.App: at android.os.Parcel.readException(Parcel.java:2340) + 06-14 13:02:41.520 19703 19703 W Networkgenie.App: at android.os.Parcel.readException(Parcel.java:2282) + 06-14 13:02:41.520 19703 19703 W Networkgenie.App: at com.android.internal.telephony.ITelephony$Stub$Proxy.getNetworkTypeForSubscriber(ITelephony.java:8711) + 06-14 13:02:41.520 19703 19703 W Networkgenie.App: at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2945) + 06-14 13:02:41.520 19703 19703 W Networkgenie.App: at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2909) */ } @@ -852,139 +844,20 @@ public class Util { return (cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED); } - public static void sendLogcat(final Uri uri, final Context context) { - AsyncTask task = new AsyncTask() { - @Override - protected Intent doInBackground(Object... objects) { - StringBuilder sb = new StringBuilder(); - sb.append(context.getString(R.string.msg_issue)); - sb.append("\r\n\r\n\r\n\r\n"); - - // Get version info - String version = getSelfVersionName(context); - sb.append(String.format("NetGuard: %s/%d\r\n", version, getSelfVersionCode(context))); - sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT)); - sb.append("\r\n"); - - // Get device info - sb.append(String.format("Brand: %s\r\n", Build.BRAND)); - sb.append(String.format("Manufacturer: %s\r\n", Build.MANUFACTURER)); - sb.append(String.format("Model: %s\r\n", Build.MODEL)); - sb.append(String.format("Product: %s\r\n", Build.PRODUCT)); - sb.append(String.format("Device: %s\r\n", Build.DEVICE)); - sb.append(String.format("Host: %s\r\n", Build.HOST)); - sb.append(String.format("Display: %s\r\n", Build.DISPLAY)); - sb.append(String.format("Id: %s\r\n", Build.ID)); - sb.append(String.format("Fingerprint: %B\r\n", hasValidFingerprint(context))); - - String abi; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) - abi = Build.CPU_ABI; - else - abi = (Build.SUPPORTED_ABIS.length > 0 ? Build.SUPPORTED_ABIS[0] : "?"); - sb.append(String.format("ABI: %s\r\n", abi)); - - Runtime rt = Runtime.getRuntime(); - long hused = (rt.totalMemory() - rt.freeMemory()) / 1024L; - long hmax = rt.maxMemory() / 1024L; - long nheap = Debug.getNativeHeapAllocatedSize() / 1024L; - NumberFormat nf = NumberFormat.getIntegerInstance(); - sb.append(String.format("Heap usage: %s/%s KiB native: %s KiB\r\n", - nf.format(hused), nf.format(hmax), nf.format(nheap))); - - sb.append("\r\n"); - - sb.append(String.format("VPN dialogs: %B\r\n", isPackageInstalled("com.android.vpndialogs", context))); - try { - sb.append(String.format("Prepared: %B\r\n", VpnService.prepare(context) == null)); - } catch (Throwable ex) { - sb.append("Prepared: ").append((ex.toString())).append("\r\n").append(Log.getStackTraceString(ex)); - } - sb.append("\r\n"); - - sb.append(getGeneralInfo(context)); - sb.append("\r\n\r\n"); - sb.append(getNetworkInfo(context)); - sb.append("\r\n\r\n"); - - // Get DNS - sb.append("DNS system:\r\n"); - for (String dns : getDefaultDNS(context)) - sb.append("- ").append(dns).append("\r\n"); - sb.append("DNS VPN:\r\n"); - for (InetAddress dns : ServiceSinkhole.getDns(context)) - sb.append("- ").append(dns).append("\r\n"); - sb.append("\r\n"); - - // Get TCP connection info - String line; - BufferedReader in; - try { - sb.append("/proc/net/tcp:\r\n"); - in = new BufferedReader(new FileReader("/proc/net/tcp")); - while ((line = in.readLine()) != null) - sb.append(line).append("\r\n"); - in.close(); - sb.append("\r\n"); - - sb.append("/proc/net/tcp6:\r\n"); - in = new BufferedReader(new FileReader("/proc/net/tcp6")); - while ((line = in.readLine()) != null) - sb.append(line).append("\r\n"); - in.close(); - sb.append("\r\n"); - - } catch (IOException ex) { - sb.append(ex.toString()).append("\r\n"); - } - - // Get settings - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - Map all = prefs.getAll(); - for (String key : all.keySet()) - sb.append("Setting: ").append(key).append('=').append(all.get(key)).append("\r\n"); - sb.append("\r\n"); - - // Write logcat - dump_memory_profile(); - OutputStream out = null; - try { - Log.i(TAG, "Writing logcat URI=" + uri); - out = context.getContentResolver().openOutputStream(uri); - out.write(getLogcat().toString().getBytes()); - out.write(getTrafficLog(context).toString().getBytes()); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - sb.append(ex.toString()).append("\r\n").append(Log.getStackTraceString(ex)).append("\r\n"); - } finally { - if (out != null) - try { - out.close(); - } catch (IOException ignored) { - } - } - - // Build intent - Intent sendEmail = new Intent(Intent.ACTION_SEND); - sendEmail.setType("message/rfc822"); - sendEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{"marcel+netguard@faircode.eu"}); - sendEmail.putExtra(Intent.EXTRA_SUBJECT, "NetGuard " + version + " logcat"); - sendEmail.putExtra(Intent.EXTRA_TEXT, sb.toString()); - sendEmail.putExtra(Intent.EXTRA_STREAM, uri); - return sendEmail; - } + public static boolean canNotify(Context context) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) + return true; + else + return (ActivityCompat.checkSelfPermission(context, + Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED); + } - @Override - protected void onPostExecute(Intent sendEmail) { - if (sendEmail != null) - try { - context.startActivity(sendEmail); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - }; - task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + public static boolean hasNewPerms(Context context) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) + return true; + else + return (ActivityCompat.checkSelfPermission(context, + Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED); } private static StringBuilder getTrafficLog(Context context) { @@ -992,20 +865,20 @@ public class Util { try (Cursor cursor = DatabaseHelper.getInstance(context).getLog(true, true, true, true, true)) { - int colTime = cursor.getColumnIndex("time"); - int colVersion = cursor.getColumnIndex("version"); - int colProtocol = cursor.getColumnIndex("protocol"); - int colFlags = cursor.getColumnIndex("flags"); - int colSAddr = cursor.getColumnIndex("saddr"); - int colSPort = cursor.getColumnIndex("sport"); - int colDAddr = cursor.getColumnIndex("daddr"); - int colDPort = cursor.getColumnIndex("dport"); - int colDName = cursor.getColumnIndex("dname"); - int colUid = cursor.getColumnIndex("uid"); - int colData = cursor.getColumnIndex("data"); - int colAllowed = cursor.getColumnIndex("allowed"); - int colConnection = cursor.getColumnIndex("connection"); - int colInteractive = cursor.getColumnIndex("interactive"); + int colTime = cursor.getColumnIndexOrThrow("time"); + int colVersion = cursor.getColumnIndexOrThrow("version"); + int colProtocol = cursor.getColumnIndexOrThrow("protocol"); + int colFlags = cursor.getColumnIndexOrThrow("flags"); + int colSAddr = cursor.getColumnIndexOrThrow("saddr"); + int colSPort = cursor.getColumnIndexOrThrow("sport"); + int colDAddr = cursor.getColumnIndexOrThrow("daddr"); + int colDPort = cursor.getColumnIndexOrThrow("dport"); + int colDName = cursor.getColumnIndexOrThrow("dname"); + int colUid = cursor.getColumnIndexOrThrow("uid"); + int colData = cursor.getColumnIndexOrThrow("data"); + int colAllowed = cursor.getColumnIndexOrThrow("allowed"); + int colConnection = cursor.getColumnIndexOrThrow("connection"); + int colInteractive = cursor.getColumnIndexOrThrow("interactive"); DateFormat format = SimpleDateFormat.getDateTimeInstance(); @@ -1031,45 +904,4 @@ public class Util { return sb; } - - private static StringBuilder getLogcat() { - StringBuilder builder = new StringBuilder(); - Process process1 = null; - Process process2 = null; - BufferedReader br = null; - try { - String[] command1 = new String[]{"logcat", "-d", "-v", "threadtime"}; - process1 = Runtime.getRuntime().exec(command1); - br = new BufferedReader(new InputStreamReader(process1.getInputStream())); - int count = 0; - String line; - while ((line = br.readLine()) != null) { - count++; - builder.append(line).append("\r\n"); - } - Log.i(TAG, "Logcat lines=" + count); - - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } finally { - if (br != null) - try { - br.close(); - } catch (IOException ignored) { - } - if (process2 != null) - try { - process2.destroy(); - } catch (Throwable ex) { - Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - if (process1 != null) - try { - process1.destroy(); - } catch (Throwable ex) { - Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - return builder; - } } diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Version.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Version.java similarity index 78% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Version.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Version.java index 7d79191..333caa4 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Version.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/Version.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ public class Version implements Comparable { diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/WidgetAdmin.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/WidgetAdmin.java similarity index 79% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/WidgetAdmin.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/WidgetAdmin.java index 02b4c98..f3cc19e 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/WidgetAdmin.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/WidgetAdmin.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.app.AlarmManager; @@ -34,13 +34,13 @@ import androidx.preference.PreferenceManager; import java.util.Date; public class WidgetAdmin extends ReceiverAutostart { - private static final String TAG = "NetGuard.Widget"; + private static final String TAG = "Networkgenie.Widget"; - public static final String INTENT_ON = "eu.faircode.netguard.ON"; - public static final String INTENT_OFF = "eu.faircode.netguard.OFF"; + public static final String INTENT_ON = "com.breakpointingbad.networkgenie.ON"; + public static final String INTENT_OFF = "com.breakpointingbad.networkgenie.OFF"; - public static final String INTENT_LOCKDOWN_ON = "eu.faircode.netguard.LOCKDOWN_ON"; - public static final String INTENT_LOCKDOWN_OFF = "eu.faircode.netguard.LOCKDOWN_OFF"; + public static final String INTENT_LOCKDOWN_ON = "com.breakpointingbad.networkgenie.LOCKDOWN_ON"; + public static final String INTENT_LOCKDOWN_OFF = "com.breakpointingbad.networkgenie.LOCKDOWN_OFF"; @Override public void onReceive(Context context, Intent intent) { @@ -55,7 +55,7 @@ public class WidgetAdmin extends ReceiverAutostart { AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(INTENT_ON); i.setPackage(context.getPackageName()); - PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); if (INTENT_ON.equals(intent.getAction()) || INTENT_OFF.equals(intent.getAction())) am.cancel(pi); diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/WidgetLockdown.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/WidgetLockdown.java similarity index 82% rename from NetworkGenie/app/src/main/main/java/eu/faircode/netguard/WidgetLockdown.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/WidgetLockdown.java index a35c01c..50ab768 100644 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/WidgetLockdown.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/WidgetLockdown.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.app.PendingIntent; @@ -32,7 +32,7 @@ import android.widget.RemoteViews; import androidx.preference.PreferenceManager; public class WidgetLockdown extends AppWidgetProvider { - private static final String TAG = "NetGuard.WidgetLock"; + private static final String TAG = "Networkgenie.WidgetLock"; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { @@ -47,7 +47,7 @@ public class WidgetLockdown extends AppWidgetProvider { try { Intent intent = new Intent(lockdown ? WidgetAdmin.INTENT_LOCKDOWN_OFF : WidgetAdmin.INTENT_LOCKDOWN_ON); intent.setPackage(context.getPackageName()); - PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); for (int id : appWidgetIds) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widgetlockdown); views.setOnClickPendingIntent(R.id.ivEnabled, pi); diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/WidgetMain.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/WidgetMain.java similarity index 82% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/WidgetMain.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/WidgetMain.java index 9e557fd..7bd73e4 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/WidgetMain.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/WidgetMain.java @@ -1,22 +1,22 @@ -package eu.faircode.netguard; +package com.breakpointingbad.networkgenie; /* - This file is part of NetGuard. + This file is part of Networkgenie. - NetGuard is free software: you can redistribute it and/or modify + Networkgenie 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, + Networkgenie 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 . + along with Networkgenie. If not, see . - Copyright 2015-2019 by Marcel Bokhorst (M66B) + Copyright 2015-2024 by Marcel Bokhorst (M66B) */ import android.app.PendingIntent; @@ -32,7 +32,7 @@ import android.widget.RemoteViews; import androidx.preference.PreferenceManager; public class WidgetMain extends AppWidgetProvider { - private static final String TAG = "NetGuard.Widget"; + private static final String TAG = "Networkgenie.Widget"; @Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { @@ -47,7 +47,7 @@ public class WidgetMain extends AppWidgetProvider { try { Intent intent = new Intent(enabled ? WidgetAdmin.INTENT_OFF : WidgetAdmin.INTENT_ON); intent.setPackage(context.getPackageName()); - PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); + PendingIntent pi = PendingIntentCompat.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); for (int id : appWidgetIds) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widgetmain); views.setOnClickPendingIntent(R.id.ivEnabled, pi); diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/compooo similarity index 99% rename from NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java rename to NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/compooo index 67cf165..edf7ff0 100644 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java +++ b/NetworkGenie/app/src/main/java/com/breakpointingbad/networkgenie/compooo @@ -1973,6 +1973,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS lock.readLock().lock(); packet.allowed = true; // flip this to false to block all traffic + // Read in ROM and decide the action to return to C function String romInfo = readRom(); System.out.println("rom info: " + romInfo + ", current send info: " + sendType + ", send conn: " + sendConn); @@ -2030,6 +2031,10 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS currConnInfo = cinfo; } + int dport = packet.dport; + if (dport == 53 || dport == 443 || dport == 80) { + genieLogPktInfo(packet); + } allowed.sender = sendConn; System.out.println("Genie handling sink pkt with daddr: " + packet.daddr + ", current genie dest: " + currGenieDestIp); System.out.println("return some allowed object: " + allowed.toString() + " for packet: " + packet); @@ -2046,6 +2051,26 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS } + private void genieLogPktInfo(Packet packet) { + + int dport = packet.dport; + int sport = packet.sport; + String ptype = "using something"; + if (dport == 80) { + ptype = "cleartext HTTP"; + } else if(dport == 443) { + ptype = "HTTPS"; + } else if(dport == 53) { + ptype = "DNS reply"; + } else if(sport == 53) { + ptype = "DNS response"; + } + DatabaseHelper dh = DatabaseHelper.getInstance(this); + String dname = dh.getQName(packet.uid, packet.daddr); + String cinfo = packet.saddr + ">" + sport + ">" + packet.daddr + ">" + dport + " TO: " + dname; + System.out.println("Genie found a packet " + ptype + ": " + cinfo + " from uid: " + packet.uid); + } + public static void updateCurrTestIp(String tconnInfo) { String[] sparts = tconnInfo.split(">"); int slen = sparts.length; @@ -2498,6 +2523,7 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS startForeground(NOTIFY_WAITING, getWaitingNotification()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + System.out.println("my genie vpn on create prefs: " + prefs.toString()); if (jni_context != 0) { Log.w(TAG, "Create with context=" + jni_context); diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityDns.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityDns.java deleted file mode 100644 index 04832cb..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityDns.java +++ /dev/null @@ -1,256 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.Intent; -import android.content.pm.PackageManager; -import android.database.Cursor; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Bundle; -import android.util.Log; -import android.util.Xml; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.widget.ListView; -import android.widget.Toast; - -import androidx.appcompat.app.AppCompatActivity; - -import org.xmlpull.v1.XmlSerializer; - -import java.io.IOException; -import java.io.OutputStream; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - -public class ActivityDns extends AppCompatActivity { - private static final String TAG = "NetGuard.DNS"; - - private static final int REQUEST_EXPORT = 1; - - private boolean running; - private AdapterDns adapter = null; - - @Override - protected void onCreate(Bundle savedInstanceState) { - Util.setTheme(this); - super.onCreate(savedInstanceState); - setContentView(R.layout.resolving); - - getSupportActionBar().setTitle(R.string.setting_show_resolved); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - ListView lvDns = findViewById(R.id.lvDns); - adapter = new AdapterDns(this, DatabaseHelper.getInstance(this).getDns()); - lvDns.setAdapter(adapter); - - running = true; - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.dns, menu); - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - PackageManager pm = getPackageManager(); - menu.findItem(R.id.menu_export).setEnabled(getIntentExport().resolveActivity(pm) != null); - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_refresh: - refresh(); - return true; - - case R.id.menu_cleanup: - cleanup(); - return true; - - case R.id.menu_clear: - Util.areYouSure(this, R.string.menu_clear, new Util.DoubtListener() { - @Override - public void onSure() { - clear(); - } - }); - return true; - - case R.id.menu_export: - export(); - return true; - } - return false; - } - - private void refresh() { - updateAdapter(); - } - - private void cleanup() { - new AsyncTask() { - @Override - protected Long doInBackground(Object... objects) { - Log.i(TAG, "Cleanup DNS"); - DatabaseHelper.getInstance(ActivityDns.this).cleanupDns(); - return null; - } - - @Override - protected void onPostExecute(Object result) { - ServiceSinkhole.reload("DNS cleanup", ActivityDns.this, false); - updateAdapter(); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void clear() { - new AsyncTask() { - @Override - protected Long doInBackground(Object... objects) { - Log.i(TAG, "Clear DNS"); - DatabaseHelper.getInstance(ActivityDns.this).clearDns(); - return null; - } - - @Override - protected void onPostExecute(Object result) { - ServiceSinkhole.reload("DNS clear", ActivityDns.this, false); - updateAdapter(); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void export() { - startActivityForResult(getIntentExport(), REQUEST_EXPORT); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - Log.i(TAG, "onActivityResult request=" + requestCode + " result=" + requestCode + " ok=" + (resultCode == RESULT_OK)); - if (requestCode == REQUEST_EXPORT) { - if (resultCode == RESULT_OK && data != null) - handleExport(data); - } - } - - private Intent getIntentExport() { - Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("*/*"); // text/xml - intent.putExtra(Intent.EXTRA_TITLE, "netguard_dns_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml"); - return intent; - } - - private void handleExport(final Intent data) { - new AsyncTask() { - @Override - protected Throwable doInBackground(Object... objects) { - OutputStream out = null; - try { - Uri target = data.getData(); - Log.i(TAG, "Writing URI=" + target); - out = getContentResolver().openOutputStream(target); - xmlExport(out); - return null; - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - return ex; - } finally { - if (out != null) - try { - out.close(); - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - } - - @Override - protected void onPostExecute(Throwable ex) { - if (running) { - if (ex == null) - Toast.makeText(ActivityDns.this, R.string.msg_completed, Toast.LENGTH_LONG).show(); - else - Toast.makeText(ActivityDns.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void xmlExport(OutputStream out) throws IOException { - XmlSerializer serializer = Xml.newSerializer(); - serializer.setOutput(out, "UTF-8"); - serializer.startDocument(null, true); - serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); - serializer.startTag(null, "netguard"); - - DateFormat df = new SimpleDateFormat("E, d MMM yyyy HH:mm:ss Z", Locale.US); // RFC 822 - - try (Cursor cursor = DatabaseHelper.getInstance(this).getDns()) { - int colTime = cursor.getColumnIndex("time"); - int colQName = cursor.getColumnIndex("qname"); - int colAName = cursor.getColumnIndex("aname"); - int colResource = cursor.getColumnIndex("resource"); - int colTTL = cursor.getColumnIndex("ttl"); - while (cursor.moveToNext()) { - long time = cursor.getLong(colTime); - String qname = cursor.getString(colQName); - String aname = cursor.getString(colAName); - String resource = cursor.getString(colResource); - int ttl = cursor.getInt(colTTL); - - serializer.startTag(null, "dns"); - serializer.attribute(null, "time", df.format(time)); - serializer.attribute(null, "qname", qname); - serializer.attribute(null, "aname", aname); - serializer.attribute(null, "resource", resource); - serializer.attribute(null, "ttl", Integer.toString(ttl)); - serializer.endTag(null, "dns"); - } - } - - serializer.endTag(null, "netguard"); - serializer.endDocument(); - serializer.flush(); - } - - private void updateAdapter() { - if (adapter != null) - adapter.changeCursor(DatabaseHelper.getInstance(this).getDns()); - } - - @Override - protected void onDestroy() { - running = false; - adapter = null; - super.onDestroy(); - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityForwarding.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityForwarding.java deleted file mode 100644 index db515a8..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityForwarding.java +++ /dev/null @@ -1,251 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.DialogInterface; -import android.database.Cursor; -import android.os.AsyncTask; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.EditText; -import android.widget.ListView; -import android.widget.PopupMenu; -import android.widget.ProgressBar; -import android.widget.Spinner; -import android.widget.Toast; - -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; - -import java.net.InetAddress; -import java.util.List; - -public class ActivityForwarding extends AppCompatActivity { - private boolean running; - private ListView lvForwarding; - private AdapterForwarding adapter; - private AlertDialog dialog = null; - - private DatabaseHelper.ForwardChangedListener listener = new DatabaseHelper.ForwardChangedListener() { - @Override - public void onChanged() { - runOnUiThread(new Runnable() { - @Override - public void run() { - if (adapter != null) - adapter.changeCursor(DatabaseHelper.getInstance(ActivityForwarding.this).getForwarding()); - } - }); - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - Util.setTheme(this); - super.onCreate(savedInstanceState); - setContentView(R.layout.forwarding); - running = true; - - getSupportActionBar().setTitle(R.string.setting_forwarding); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - - lvForwarding = findViewById(R.id.lvForwarding); - adapter = new AdapterForwarding(this, DatabaseHelper.getInstance(this).getForwarding()); - lvForwarding.setAdapter(adapter); - - lvForwarding.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - Cursor cursor = (Cursor) adapter.getItem(position); - final int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); - final int dport = cursor.getInt(cursor.getColumnIndex("dport")); - final String raddr = cursor.getString(cursor.getColumnIndex("raddr")); - final int rport = cursor.getInt(cursor.getColumnIndex("rport")); - - PopupMenu popup = new PopupMenu(ActivityForwarding.this, view); - popup.inflate(R.menu.forward); - popup.getMenu().findItem(R.id.menu_port).setTitle( - Util.getProtocolName(protocol, 0, false) + " " + - dport + " > " + raddr + "/" + rport); - - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - if (menuItem.getItemId() == R.id.menu_delete) { - DatabaseHelper.getInstance(ActivityForwarding.this).deleteForward(protocol, dport); - ServiceSinkhole.reload("forwarding", ActivityForwarding.this, false); - adapter = new AdapterForwarding(ActivityForwarding.this, - DatabaseHelper.getInstance(ActivityForwarding.this).getForwarding()); - lvForwarding.setAdapter(adapter); - } - return false; - } - }); - - popup.show(); - } - }); - } - - @Override - protected void onResume() { - super.onResume(); - DatabaseHelper.getInstance(this).addForwardChangedListener(listener); - if (adapter != null) - adapter.changeCursor(DatabaseHelper.getInstance(ActivityForwarding.this).getForwarding()); - } - - @Override - protected void onPause() { - super.onPause(); - DatabaseHelper.getInstance(this).removeForwardChangedListener(listener); - } - - @Override - protected void onDestroy() { - running = false; - adapter = null; - if (dialog != null) { - dialog.dismiss(); - dialog = null; - } - super.onDestroy(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.forwarding, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.menu_add: - LayoutInflater inflater = LayoutInflater.from(this); - View view = inflater.inflate(R.layout.forwardadd, null, false); - final Spinner spProtocol = view.findViewById(R.id.spProtocol); - final EditText etDPort = view.findViewById(R.id.etDPort); - final EditText etRAddr = view.findViewById(R.id.etRAddr); - final EditText etRPort = view.findViewById(R.id.etRPort); - final ProgressBar pbRuid = view.findViewById(R.id.pbRUid); - final Spinner spRuid = view.findViewById(R.id.spRUid); - - final AsyncTask task = new AsyncTask>() { - @Override - protected void onPreExecute() { - pbRuid.setVisibility(View.VISIBLE); - spRuid.setVisibility(View.GONE); - } - - @Override - protected List doInBackground(Object... objects) { - return Rule.getRules(true, ActivityForwarding.this); - } - - @Override - protected void onPostExecute(List rules) { - ArrayAdapter spinnerArrayAdapter = - new ArrayAdapter(ActivityForwarding.this, - android.R.layout.simple_spinner_item, rules); - spRuid.setAdapter(spinnerArrayAdapter); - pbRuid.setVisibility(View.GONE); - spRuid.setVisibility(View.VISIBLE); - } - }; - task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - - dialog = new AlertDialog.Builder(this) - .setView(view) - .setCancelable(true) - .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - try { - int pos = spProtocol.getSelectedItemPosition(); - String[] values = getResources().getStringArray(R.array.protocolValues); - final int protocol = Integer.valueOf(values[pos]); - final int dport = Integer.parseInt(etDPort.getText().toString()); - final String raddr = etRAddr.getText().toString(); - final int rport = Integer.parseInt(etRPort.getText().toString()); - final int ruid = ((Rule) spRuid.getSelectedItem()).uid; - - InetAddress iraddr = InetAddress.getByName(raddr); - if (rport < 1024 && (iraddr.isLoopbackAddress() || iraddr.isAnyLocalAddress())) - throw new IllegalArgumentException("Port forwarding to privileged port on local address not possible"); - - new AsyncTask() { - @Override - protected Throwable doInBackground(Object... objects) { - try { - DatabaseHelper.getInstance(ActivityForwarding.this) - .addForward(protocol, dport, raddr, rport, ruid); - return null; - } catch (Throwable ex) { - return ex; - } - } - - @Override - protected void onPostExecute(Throwable ex) { - if (running) - if (ex == null) { - ServiceSinkhole.reload("forwarding", ActivityForwarding.this, false); - adapter = new AdapterForwarding(ActivityForwarding.this, - DatabaseHelper.getInstance(ActivityForwarding.this).getForwarding()); - lvForwarding.setAdapter(adapter); - } else - Toast.makeText(ActivityForwarding.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } catch (Throwable ex) { - Toast.makeText(ActivityForwarding.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - } - }) - .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - task.cancel(false); - dialog.dismiss(); - } - }) - .setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialogInterface) { - dialog = null; - } - }) - .create(); - dialog.show(); - return true; - default: - return super.onOptionsItemSelected(item); - } - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityLog.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityLog.java deleted file mode 100644 index 5380108..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivityLog.java +++ /dev/null @@ -1,643 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.PackageManager; -import android.database.Cursor; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.text.TextUtils; -import android.util.Log; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.AdapterView; -import android.widget.CompoundButton; -import android.widget.FilterQueryProvider; -import android.widget.ListView; -import android.widget.PopupMenu; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.SearchView; -import androidx.appcompat.widget.SwitchCompat; -import androidx.core.app.NavUtils; -import androidx.preference.PreferenceManager; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class ActivityLog extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.Log"; - - private boolean running = false; - private ListView lvLog; - private AdapterLog adapter; - private MenuItem menuSearch = null; - - private boolean live; - private boolean resolve; - private boolean organization; - private InetAddress vpn4 = null; - private InetAddress vpn6 = null; - - private static final int REQUEST_PCAP = 1; - - private DatabaseHelper.LogChangedListener listener = new DatabaseHelper.LogChangedListener() { - @Override - public void onChanged() { - runOnUiThread(new Runnable() { - @Override - public void run() { - updateAdapter(); - } - }); - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - if (!IAB.isPurchased(ActivityPro.SKU_LOG, this)) { - startActivity(new Intent(this, ActivityPro.class)); - finish(); - } - - Util.setTheme(this); - super.onCreate(savedInstanceState); - setContentView(R.layout.logging); - running = true; - - // Action bar - View actionView = getLayoutInflater().inflate(R.layout.actionlog, null, false); - SwitchCompat swEnabled = actionView.findViewById(R.id.swEnabled); - - getSupportActionBar().setDisplayShowCustomEnabled(true); - getSupportActionBar().setCustomView(actionView); - - getSupportActionBar().setTitle(R.string.menu_log); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - // Get settings - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - resolve = prefs.getBoolean("resolve", false); - organization = prefs.getBoolean("organization", false); - boolean log = prefs.getBoolean("log", false); - - // Show disabled message - TextView tvDisabled = findViewById(R.id.tvDisabled); - tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); - - // Set enabled switch - swEnabled.setChecked(log); - swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - prefs.edit().putBoolean("log", isChecked).apply(); - } - }); - - // Listen for preference changes - prefs.registerOnSharedPreferenceChangeListener(this); - - lvLog = findViewById(R.id.lvLog); - - boolean udp = prefs.getBoolean("proto_udp", true); - boolean tcp = prefs.getBoolean("proto_tcp", true); - boolean other = prefs.getBoolean("proto_other", true); - boolean allowed = prefs.getBoolean("traffic_allowed", true); - boolean blocked = prefs.getBoolean("traffic_blocked", true); - - adapter = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve, organization); - adapter.setFilterQueryProvider(new FilterQueryProvider() { - public Cursor runQuery(CharSequence constraint) { - return DatabaseHelper.getInstance(ActivityLog.this).searchLog(constraint.toString()); - } - }); - - lvLog.setAdapter(adapter); - - try { - vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); - vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); - } catch (UnknownHostException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - lvLog.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - PackageManager pm = getPackageManager(); - Cursor cursor = (Cursor) adapter.getItem(position); - long time = cursor.getLong(cursor.getColumnIndex("time")); - int version = cursor.getInt(cursor.getColumnIndex("version")); - int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); - final String saddr = cursor.getString(cursor.getColumnIndex("saddr")); - final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport"))); - final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); - final int dport = (cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport"))); - final String dname = cursor.getString(cursor.getColumnIndex("dname")); - final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"))); - int allowed = (cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed"))); - - // Get external address - InetAddress addr = null; - try { - addr = InetAddress.getByName(daddr); - } catch (UnknownHostException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - String ip; - int port; - if (addr.equals(vpn4) || addr.equals(vpn6)) { - ip = saddr; - port = sport; - } else { - ip = daddr; - port = dport; - } - - // Build popup menu - PopupMenu popup = new PopupMenu(ActivityLog.this, findViewById(R.id.vwPopupAnchor)); - popup.inflate(R.menu.log); - - // Application name - if (uid >= 0) - popup.getMenu().findItem(R.id.menu_application).setTitle(TextUtils.join(", ", Util.getApplicationNames(uid, ActivityLog.this))); - else - popup.getMenu().removeItem(R.id.menu_application); - - // Destination IP - popup.getMenu().findItem(R.id.menu_protocol).setTitle(Util.getProtocolName(protocol, version, false)); - - // Whois - final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.dnslytics.com/whois-lookup/" + ip)); - if (pm.resolveActivity(lookupIP, 0) == null) - popup.getMenu().removeItem(R.id.menu_whois); - else - popup.getMenu().findItem(R.id.menu_whois).setTitle(getString(R.string.title_log_whois, ip)); - - // Lookup port - final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.speedguide.net/port.php?port=" + port)); - if (port <= 0 || pm.resolveActivity(lookupPort, 0) == null) - popup.getMenu().removeItem(R.id.menu_port); - else - popup.getMenu().findItem(R.id.menu_port).setTitle(getString(R.string.title_log_port, port)); - - if (prefs.getBoolean("filter", false)) { - if (uid <= 0) { - popup.getMenu().removeItem(R.id.menu_allow); - popup.getMenu().removeItem(R.id.menu_block); - } - } else { - popup.getMenu().removeItem(R.id.menu_allow); - popup.getMenu().removeItem(R.id.menu_block); - } - - final Packet packet = new Packet(); - packet.version = version; - packet.protocol = protocol; - packet.daddr = daddr; - packet.dport = dport; - packet.time = time; - packet.uid = uid; - packet.allowed = (allowed > 0); - - // Time - popup.getMenu().findItem(R.id.menu_time).setTitle(SimpleDateFormat.getDateTimeInstance().format(time)); - - // Handle click - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - switch (menuItem.getItemId()) { - case R.id.menu_application: { - Intent main = new Intent(ActivityLog.this, ActivityMain.class); - main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); - startActivity(main); - return true; - } - - case R.id.menu_whois: - startActivity(lookupIP); - return true; - - case R.id.menu_port: - startActivity(lookupPort); - return true; - - case R.id.menu_allow: - if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) { - DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 0); - ServiceSinkhole.reload("allow host", ActivityLog.this, false); - Intent main = new Intent(ActivityLog.this, ActivityMain.class); - main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); - startActivity(main); - } else - startActivity(new Intent(ActivityLog.this, ActivityPro.class)); - return true; - - case R.id.menu_block: - if (IAB.isPurchased(ActivityPro.SKU_FILTER, ActivityLog.this)) { - DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 1); - ServiceSinkhole.reload("block host", ActivityLog.this, false); - Intent main = new Intent(ActivityLog.this, ActivityMain.class); - main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); - startActivity(main); - } else - startActivity(new Intent(ActivityLog.this, ActivityPro.class)); - return true; - - case R.id.menu_copy: - ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("netguard", dname == null ? daddr : dname); - clipboard.setPrimaryClip(clip); - return true; - - default: - return false; - } - } - }); - - // Show - popup.show(); - } - }); - - live = true; - } - - @Override - protected void onResume() { - super.onResume(); - if (live) { - DatabaseHelper.getInstance(this).addLogChangedListener(listener); - updateAdapter(); - } - } - - @Override - protected void onPause() { - super.onPause(); - if (live) - DatabaseHelper.getInstance(this).removeLogChangedListener(listener); - } - - @Override - protected void onDestroy() { - running = false; - adapter = null; - PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this); - super.onDestroy(); - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { - Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name)); - if ("log".equals(name)) { - // Get enabled - boolean log = prefs.getBoolean(name, false); - - // Display disabled warning - TextView tvDisabled = findViewById(R.id.tvDisabled); - tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); - - // Check switch state - SwitchCompat swEnabled = getSupportActionBar().getCustomView().findViewById(R.id.swEnabled); - if (swEnabled.isChecked() != log) - swEnabled.setChecked(log); - - ServiceSinkhole.reload("changed " + name, ActivityLog.this, false); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.logging, menu); - - menuSearch = menu.findItem(R.id.menu_search); - SearchView searchView = (SearchView) menuSearch.getActionView(); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String query) { - if (adapter != null) - adapter.getFilter().filter(getUidForName(query)); - return true; - } - - @Override - public boolean onQueryTextChange(String newText) { - if (adapter != null) - adapter.getFilter().filter(getUidForName(newText)); - return true; - } - }); - searchView.setOnCloseListener(new SearchView.OnCloseListener() { - @Override - public boolean onClose() { - if (adapter != null) - adapter.getFilter().filter(null); - return true; - } - }); - - return true; - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - - // https://gist.github.com/granoeste/5574148 - File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); - - boolean export = (getPackageManager().resolveActivity(getIntentPCAPDocument(), 0) != null); - - menu.findItem(R.id.menu_protocol_udp).setChecked(prefs.getBoolean("proto_udp", true)); - menu.findItem(R.id.menu_protocol_tcp).setChecked(prefs.getBoolean("proto_tcp", true)); - menu.findItem(R.id.menu_protocol_other).setChecked(prefs.getBoolean("proto_other", true)); - menu.findItem(R.id.menu_traffic_allowed).setEnabled(prefs.getBoolean("filter", false)); - menu.findItem(R.id.menu_traffic_allowed).setChecked(prefs.getBoolean("traffic_allowed", true)); - menu.findItem(R.id.menu_traffic_blocked).setChecked(prefs.getBoolean("traffic_blocked", true)); - - menu.findItem(R.id.menu_refresh).setEnabled(!menu.findItem(R.id.menu_log_live).isChecked()); - menu.findItem(R.id.menu_log_resolve).setChecked(prefs.getBoolean("resolve", false)); - menu.findItem(R.id.menu_log_organization).setChecked(prefs.getBoolean("organization", false)); - menu.findItem(R.id.menu_pcap_enabled).setChecked(prefs.getBoolean("pcap", false)); - menu.findItem(R.id.menu_pcap_export).setEnabled(pcap_file.exists() && export); - - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - final File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); - - switch (item.getItemId()) { - case android.R.id.home: - Log.i(TAG, "Up"); - NavUtils.navigateUpFromSameTask(this); - return true; - - case R.id.menu_protocol_udp: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("proto_udp", item.isChecked()).apply(); - updateAdapter(); - return true; - - case R.id.menu_protocol_tcp: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("proto_tcp", item.isChecked()).apply(); - updateAdapter(); - return true; - - case R.id.menu_protocol_other: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("proto_other", item.isChecked()).apply(); - updateAdapter(); - return true; - - case R.id.menu_traffic_allowed: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("traffic_allowed", item.isChecked()).apply(); - updateAdapter(); - return true; - - case R.id.menu_traffic_blocked: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("traffic_blocked", item.isChecked()).apply(); - updateAdapter(); - return true; - - case R.id.menu_log_live: - item.setChecked(!item.isChecked()); - live = item.isChecked(); - if (live) { - DatabaseHelper.getInstance(this).addLogChangedListener(listener); - updateAdapter(); - } else - DatabaseHelper.getInstance(this).removeLogChangedListener(listener); - return true; - - case R.id.menu_refresh: - updateAdapter(); - return true; - - case R.id.menu_log_resolve: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("resolve", item.isChecked()).apply(); - adapter.setResolve(item.isChecked()); - adapter.notifyDataSetChanged(); - return true; - - case R.id.menu_log_organization: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("organization", item.isChecked()).apply(); - adapter.setOrganization(item.isChecked()); - adapter.notifyDataSetChanged(); - return true; - - case R.id.menu_pcap_enabled: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("pcap", item.isChecked()).apply(); - ServiceSinkhole.setPcap(item.isChecked(), ActivityLog.this); - return true; - - case R.id.menu_pcap_export: - startActivityForResult(getIntentPCAPDocument(), REQUEST_PCAP); - return true; - - case R.id.menu_log_clear: - new AsyncTask() { - @Override - protected Object doInBackground(Object... objects) { - DatabaseHelper.getInstance(ActivityLog.this).clearLog(-1); - if (prefs.getBoolean("pcap", false)) { - ServiceSinkhole.setPcap(false, ActivityLog.this); - if (pcap_file.exists() && !pcap_file.delete()) - Log.w(TAG, "Delete PCAP failed"); - ServiceSinkhole.setPcap(true, ActivityLog.this); - } else { - if (pcap_file.exists() && !pcap_file.delete()) - Log.w(TAG, "Delete PCAP failed"); - } - return null; - } - - @Override - protected void onPostExecute(Object result) { - if (running) - updateAdapter(); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - return true; - - case R.id.menu_log_support: - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq27")); - if (getPackageManager().resolveActivity(intent, 0) != null) - startActivity(intent); - return true; - - default: - return super.onOptionsItemSelected(item); - } - } - - private void updateAdapter() { - if (adapter != null) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean udp = prefs.getBoolean("proto_udp", true); - boolean tcp = prefs.getBoolean("proto_tcp", true); - boolean other = prefs.getBoolean("proto_other", true); - boolean allowed = prefs.getBoolean("traffic_allowed", true); - boolean blocked = prefs.getBoolean("traffic_blocked", true); - adapter.changeCursor(DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked)); - if (menuSearch != null && menuSearch.isActionViewExpanded()) { - SearchView searchView = (SearchView) menuSearch.getActionView(); - adapter.getFilter().filter(getUidForName(searchView.getQuery().toString())); - } - } - } - - private String getUidForName(String query) { - if (query != null && query.length() > 0) { - for (Rule rule : Rule.getRules(true, ActivityLog.this)) - if (rule.name != null && rule.name.toLowerCase().contains(query.toLowerCase())) { - String newQuery = Integer.toString(rule.uid); - Log.i(TAG, "Search " + query + " found " + rule.name + " new " + newQuery); - return newQuery; - } - Log.i(TAG, "Search " + query + " not found"); - } - return query; - } - - private Intent getIntentPCAPDocument() { - Intent intent; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - if (Util.isPackageInstalled("org.openintents.filemanager", this)) { - intent = new Intent("org.openintents.action.PICK_DIRECTORY"); - } else { - intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=org.openintents.filemanager")); - } - } else { - intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("application/octet-stream"); - intent.putExtra(Intent.EXTRA_TITLE, "netguard_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".pcap"); - } - return intent; - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, final Intent data) { - Log.i(TAG, "onActivityResult request=" + requestCode + " result=" + requestCode + " ok=" + (resultCode == RESULT_OK)); - - if (requestCode == REQUEST_PCAP) { - if (resultCode == RESULT_OK && data != null) - handleExportPCAP(data); - - } else { - Log.w(TAG, "Unknown activity result request=" + requestCode); - super.onActivityResult(requestCode, resultCode, data); - } - } - - private void handleExportPCAP(final Intent data) { - new AsyncTask() { - @Override - protected Throwable doInBackground(Object... objects) { - OutputStream out = null; - FileInputStream in = null; - try { - // Stop capture - ServiceSinkhole.setPcap(false, ActivityLog.this); - - Uri target = data.getData(); - if (data.hasExtra("org.openintents.extra.DIR_PATH")) - target = Uri.parse(target + "/netguard.pcap"); - Log.i(TAG, "Export PCAP URI=" + target); - out = getContentResolver().openOutputStream(target); - - File pcap = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); - in = new FileInputStream(pcap); - - int len; - long total = 0; - byte[] buf = new byte[4096]; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - total += len; - } - Log.i(TAG, "Copied bytes=" + total); - - return null; - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - return ex; - } finally { - if (out != null) - try { - out.close(); - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - if (in != null) - try { - in.close(); - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - // Resume capture - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivityLog.this); - if (prefs.getBoolean("pcap", false)) - ServiceSinkhole.setPcap(true, ActivityLog.this); - } - } - - @Override - protected void onPostExecute(Throwable ex) { - if (ex == null) - Toast.makeText(ActivityLog.this, R.string.msg_completed, Toast.LENGTH_LONG).show(); - else - Toast.makeText(ActivityLog.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivitySettings.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivitySettings.java deleted file mode 100644 index 5c38150..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ActivitySettings.java +++ /dev/null @@ -1,1466 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.Manifest; -import android.annotation.TargetApi; -import android.content.BroadcastReceiver; -import android.content.ContentResolver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.content.pm.PackageManager; -import android.content.res.AssetFileDescriptor; -import android.database.Cursor; -import android.net.ConnectivityManager; -import android.net.Uri; -import android.net.wifi.WifiConfiguration; -import android.net.wifi.WifiManager; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.preference.EditTextPreference; -import android.preference.ListPreference; -import android.preference.MultiSelectListPreference; -import android.preference.Preference; -import android.preference.PreferenceFragment; -import android.preference.PreferenceGroup; -import android.preference.PreferenceScreen; -import android.preference.TwoStatePreference; -import android.text.SpannableStringBuilder; -import android.text.Spanned; -import android.text.TextUtils; -import android.text.style.ImageSpan; -import android.util.Log; -import android.util.Xml; -import android.view.LayoutInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.NavUtils; -import androidx.core.util.PatternsCompat; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import androidx.preference.PreferenceManager; - -import org.xml.sax.Attributes; -import org.xml.sax.InputSource; -import org.xml.sax.SAXException; -import org.xml.sax.XMLReader; -import org.xml.sax.helpers.DefaultHandler; -import org.xmlpull.v1.XmlSerializer; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.InetAddress; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.UnknownHostException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParserFactory; - -public class ActivitySettings extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.Settings"; - - private boolean running = false; - - private static final int REQUEST_EXPORT = 1; - private static final int REQUEST_IMPORT = 2; - private static final int REQUEST_HOSTS = 3; - private static final int REQUEST_HOSTS_APPEND = 4; - private static final int REQUEST_CALL = 5; - - private AlertDialog dialogFilter = null; - - private static final Intent INTENT_VPN_SETTINGS = new Intent("android.net.vpn.SETTINGS"); - - protected void onCreate(Bundle savedInstanceState) { - Util.setTheme(this); - super.onCreate(savedInstanceState); - getFragmentManager().beginTransaction().replace(android.R.id.content, new FragmentSettings()).commit(); - getSupportActionBar().setTitle(R.string.menu_settings); - running = true; - } - - private PreferenceScreen getPreferenceScreen() { - return ((PreferenceFragment) getFragmentManager().findFragmentById(android.R.id.content)).getPreferenceScreen(); - } - - @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); - final PreferenceScreen screen = getPreferenceScreen(); - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - - PreferenceGroup cat_options = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_options")).findPreference("category_options"); - PreferenceGroup cat_network = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_network_options")).findPreference("category_network_options"); - PreferenceGroup cat_advanced = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_advanced_options")).findPreference("category_advanced_options"); - PreferenceGroup cat_stats = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_stats")).findPreference("category_stats"); - PreferenceGroup cat_backup = (PreferenceGroup) ((PreferenceGroup) screen.findPreference("screen_backup")).findPreference("category_backup"); - - // Handle auto enable - Preference pref_auto_enable = screen.findPreference("auto_enable"); - pref_auto_enable.setTitle(getString(R.string.setting_auto, prefs.getString("auto_enable", "0"))); - - // Handle screen delay - Preference pref_screen_delay = screen.findPreference("screen_delay"); - pref_screen_delay.setTitle(getString(R.string.setting_delay, prefs.getString("screen_delay", "0"))); - - // Handle theme - Preference pref_screen_theme = screen.findPreference("theme"); - String theme = prefs.getString("theme", "teal"); - String[] themeNames = getResources().getStringArray(R.array.themeNames); - String[] themeValues = getResources().getStringArray(R.array.themeValues); - for (int i = 0; i < themeNames.length; i++) - if (theme.equals(themeValues[i])) { - pref_screen_theme.setTitle(getString(R.string.setting_theme, themeNames[i])); - break; - } - - // Wi-Fi home - MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) screen.findPreference("wifi_homes"); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) - cat_network.removePreference(pref_wifi_homes); - else { - Set ssids = prefs.getStringSet("wifi_homes", new HashSet()); - if (ssids.size() > 0) - pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssids))); - else - pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-")); - - WifiManager wm = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); - List listSSID = new ArrayList<>(); - List configs = wm.getConfiguredNetworks(); - if (configs != null) - for (WifiConfiguration config : configs) - listSSID.add(config.SSID == null ? "NULL" : config.SSID); - for (String ssid : ssids) - if (!listSSID.contains(ssid)) - listSSID.add(ssid); - pref_wifi_homes.setEntries(listSSID.toArray(new CharSequence[0])); - pref_wifi_homes.setEntryValues(listSSID.toArray(new CharSequence[0])); - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - TwoStatePreference pref_handover = - (TwoStatePreference) screen.findPreference("handover"); - cat_advanced.removePreference(pref_handover); - } - - Preference pref_reset_usage = screen.findPreference("reset_usage"); - pref_reset_usage.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - Util.areYouSure(ActivitySettings.this, R.string.setting_reset_usage, new Util.DoubtListener() { - @Override - public void onSure() { - new AsyncTask() { - @Override - protected Throwable doInBackground(Object... objects) { - try { - DatabaseHelper.getInstance(ActivitySettings.this).resetUsage(-1); - return null; - } catch (Throwable ex) { - return ex; - } - } - - @Override - protected void onPostExecute(Throwable ex) { - if (ex == null) - Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show(); - else - Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - }); - return false; - } - }); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - TwoStatePreference pref_reload_onconnectivity = - (TwoStatePreference) screen.findPreference("reload_onconnectivity"); - pref_reload_onconnectivity.setChecked(true); - pref_reload_onconnectivity.setEnabled(false); - } - - // Handle port forwarding - Preference pref_forwarding = screen.findPreference("forwarding"); - pref_forwarding.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - startActivity(new Intent(ActivitySettings.this, ActivityForwarding.class)); - return true; - } - }); - - boolean can = Util.canFilter(this); - TwoStatePreference pref_log_app = (TwoStatePreference) screen.findPreference("log_app"); - TwoStatePreference pref_filter = (TwoStatePreference) screen.findPreference("filter"); - pref_log_app.setEnabled(can); - pref_filter.setEnabled(can); - if (!can) { - pref_log_app.setSummary(R.string.msg_unavailable); - pref_filter.setSummary(R.string.msg_unavailable); - } - - // VPN parameters - screen.findPreference("vpn4").setTitle(getString(R.string.setting_vpn4, prefs.getString("vpn4", "10.1.10.1"))); - screen.findPreference("vpn6").setTitle(getString(R.string.setting_vpn6, prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1"))); - EditTextPreference pref_dns1 = (EditTextPreference) screen.findPreference("dns"); - EditTextPreference pref_dns2 = (EditTextPreference) screen.findPreference("dns2"); - EditTextPreference pref_validate = (EditTextPreference) screen.findPreference("validate"); - EditTextPreference pref_ttl = (EditTextPreference) screen.findPreference("ttl"); - pref_dns1.setTitle(getString(R.string.setting_dns, prefs.getString("dns", "-"))); - pref_dns2.setTitle(getString(R.string.setting_dns, prefs.getString("dns2", "-"))); - pref_validate.setTitle(getString(R.string.setting_validate, prefs.getString("validate", "www.google.com"))); - pref_ttl.setTitle(getString(R.string.setting_ttl, prefs.getString("ttl", "259200"))); - - // SOCKS5 parameters - screen.findPreference("socks5_addr").setTitle(getString(R.string.setting_socks5_addr, prefs.getString("socks5_addr", "-"))); - screen.findPreference("socks5_port").setTitle(getString(R.string.setting_socks5_port, prefs.getString("socks5_port", "-"))); - screen.findPreference("socks5_username").setTitle(getString(R.string.setting_socks5_username, prefs.getString("socks5_username", "-"))); - screen.findPreference("socks5_password").setTitle(getString(R.string.setting_socks5_password, TextUtils.isEmpty(prefs.getString("socks5_username", "")) ? "-" : "*****")); - - // PCAP parameters - screen.findPreference("pcap_record_size").setTitle(getString(R.string.setting_pcap_record_size, prefs.getString("pcap_record_size", "64"))); - screen.findPreference("pcap_file_size").setTitle(getString(R.string.setting_pcap_file_size, prefs.getString("pcap_file_size", "2"))); - - // Watchdog - screen.findPreference("watchdog").setTitle(getString(R.string.setting_watchdog, prefs.getString("watchdog", "0"))); - - // Show resolved - Preference pref_show_resolved = screen.findPreference("show_resolved"); - if (Util.isPlayStoreInstall(this)) - cat_advanced.removePreference(pref_show_resolved); - else - pref_show_resolved.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - startActivity(new Intent(ActivitySettings.this, ActivityDns.class)); - return true; - } - }); - - // Handle stats - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - cat_stats.removePreference(screen.findPreference("show_top")); - EditTextPreference pref_stats_frequency = (EditTextPreference) screen.findPreference("stats_frequency"); - EditTextPreference pref_stats_samples = (EditTextPreference) screen.findPreference("stats_samples"); - pref_stats_frequency.setTitle(getString(R.string.setting_stats_frequency, prefs.getString("stats_frequency", "1000"))); - pref_stats_samples.setTitle(getString(R.string.setting_stats_samples, prefs.getString("stats_samples", "90"))); - - // Handle export - Preference pref_export = screen.findPreference("export"); - pref_export.setEnabled(getIntentCreateExport().resolveActivity(getPackageManager()) != null); - pref_export.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - startActivityForResult(getIntentCreateExport(), ActivitySettings.REQUEST_EXPORT); - return true; - } - }); - - // Handle import - Preference pref_import = screen.findPreference("import"); - pref_import.setEnabled(getIntentOpenExport().resolveActivity(getPackageManager()) != null); - pref_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - startActivityForResult(getIntentOpenExport(), ActivitySettings.REQUEST_IMPORT); - return true; - } - }); - - // Hosts file settings - Preference pref_block_domains = screen.findPreference("use_hosts"); - EditTextPreference pref_rcode = (EditTextPreference) screen.findPreference("rcode"); - Preference pref_hosts_import = screen.findPreference("hosts_import"); - Preference pref_hosts_import_append = screen.findPreference("hosts_import_append"); - EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url"); - final Preference pref_hosts_download = screen.findPreference("hosts_download"); - - pref_rcode.setTitle(getString(R.string.setting_rcode, prefs.getString("rcode", "3"))); - - if (Util.isPlayStoreInstall(this) || !Util.hasValidFingerprint(this)) - cat_options.removePreference(screen.findPreference("update_check")); - - if (Util.isPlayStoreInstall(this)) { - Log.i(TAG, "Play store install"); - cat_advanced.removePreference(pref_block_domains); - cat_advanced.removePreference(pref_rcode); - cat_advanced.removePreference(pref_forwarding); - cat_backup.removePreference(pref_hosts_import); - cat_backup.removePreference(pref_hosts_import_append); - cat_backup.removePreference(pref_hosts_url); - cat_backup.removePreference(pref_hosts_download); - - } else { - String last_import = prefs.getString("hosts_last_import", null); - String last_download = prefs.getString("hosts_last_download", null); - if (last_import != null) - pref_hosts_import.setSummary(getString(R.string.msg_import_last, last_import)); - if (last_download != null) - pref_hosts_download.setSummary(getString(R.string.msg_download_last, last_download)); - - // Handle hosts import - // https://github.com/Free-Software-for-Android/AdAway/wiki/HostsSources - pref_hosts_import.setEnabled(getIntentOpenHosts().resolveActivity(getPackageManager()) != null); - pref_hosts_import.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - startActivityForResult(getIntentOpenHosts(), ActivitySettings.REQUEST_HOSTS); - return true; - } - }); - pref_hosts_import_append.setEnabled(pref_hosts_import.isEnabled()); - pref_hosts_import_append.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - startActivityForResult(getIntentOpenHosts(), ActivitySettings.REQUEST_HOSTS_APPEND); - return true; - } - }); - - // Handle hosts file download - pref_hosts_url.setSummary(pref_hosts_url.getText()); - pref_hosts_download.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - final File tmp = new File(getFilesDir(), "hosts.tmp"); - final File hosts = new File(getFilesDir(), "hosts.txt"); - - EditTextPreference pref_hosts_url = (EditTextPreference) screen.findPreference("hosts_url"); - String hosts_url = pref_hosts_url.getText(); - if ("https://www.netguard.me/hosts".equals(hosts_url)) - hosts_url = BuildConfig.HOSTS_FILE_URI; - - try { - new DownloadTask(ActivitySettings.this, new URL(hosts_url), tmp, new DownloadTask.Listener() { - @Override - public void onCompleted() { - if (hosts.exists()) - hosts.delete(); - tmp.renameTo(hosts); - - String last = SimpleDateFormat.getDateTimeInstance().format(new Date().getTime()); - prefs.edit().putString("hosts_last_download", last).apply(); - - if (running) { - pref_hosts_download.setSummary(getString(R.string.msg_download_last, last)); - Toast.makeText(ActivitySettings.this, R.string.msg_downloaded, Toast.LENGTH_LONG).show(); - } - - ServiceSinkhole.reload("hosts file download", ActivitySettings.this, false); - } - - @Override - public void onCancelled() { - if (tmp.exists()) - tmp.delete(); - } - - @Override - public void onException(Throwable ex) { - if (tmp.exists()) - tmp.delete(); - - if (running) - Toast.makeText(ActivitySettings.this, ex.getMessage(), Toast.LENGTH_LONG).show(); - } - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } catch (MalformedURLException ex) { - Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - return true; - } - }); - } - - // Development - if (!Util.isDebuggable(this)) - screen.removePreference(screen.findPreference("screen_development")); - - // Handle technical info - Preference.OnPreferenceClickListener listener = new Preference.OnPreferenceClickListener() { - @Override - public boolean onPreferenceClick(Preference preference) { - updateTechnicalInfo(); - return true; - } - }; - - // Technical info - Preference pref_technical_info = screen.findPreference("technical_info"); - Preference pref_technical_network = screen.findPreference("technical_network"); - pref_technical_info.setEnabled(INTENT_VPN_SETTINGS.resolveActivity(this.getPackageManager()) != null); - pref_technical_info.setIntent(INTENT_VPN_SETTINGS); - pref_technical_info.setOnPreferenceClickListener(listener); - pref_technical_network.setOnPreferenceClickListener(listener); - updateTechnicalInfo(); - - markPro(screen.findPreference("theme"), ActivityPro.SKU_THEME); - markPro(screen.findPreference("install"), ActivityPro.SKU_NOTIFY); - markPro(screen.findPreference("show_stats"), ActivityPro.SKU_SPEED); - } - - @Override - protected void onResume() { - super.onResume(); - - checkPermissions(null); - - // Listen for preference changes - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.registerOnSharedPreferenceChangeListener(this); - - // Listen for interactive state changes - IntentFilter ifInteractive = new IntentFilter(); - ifInteractive.addAction(Intent.ACTION_SCREEN_ON); - ifInteractive.addAction(Intent.ACTION_SCREEN_OFF); - registerReceiver(interactiveStateReceiver, ifInteractive); - - // Listen for connectivity updates - IntentFilter ifConnectivity = new IntentFilter(); - ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION); - registerReceiver(connectivityChangedReceiver, ifConnectivity); - } - - @Override - protected void onPause() { - super.onPause(); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.unregisterOnSharedPreferenceChangeListener(this); - - unregisterReceiver(interactiveStateReceiver); - unregisterReceiver(connectivityChangedReceiver); - } - - @Override - protected void onDestroy() { - running = false; - if (dialogFilter != null) { - dialogFilter.dismiss(); - dialogFilter = null; - } - super.onDestroy(); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - Log.i(TAG, "Up"); - NavUtils.navigateUpFromSameTask(this); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - - @Override - @TargetApi(Build.VERSION_CODES.M) - public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { - // Pro features - if ("theme".equals(name)) { - if (!"teal".equals(prefs.getString(name, "teal")) && !IAB.isPurchased(ActivityPro.SKU_THEME, this)) { - prefs.edit().putString(name, "teal").apply(); - ((ListPreference) getPreferenceScreen().findPreference(name)).setValue("teal"); - startActivity(new Intent(this, ActivityPro.class)); - return; - } - } else if ("install".equals(name)) { - if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_NOTIFY, this)) { - prefs.edit().putBoolean(name, false).apply(); - ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(false); - startActivity(new Intent(this, ActivityPro.class)); - return; - } - } else if ("show_stats".equals(name)) { - if (prefs.getBoolean(name, false) && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) { - prefs.edit().putBoolean(name, false).apply(); - startActivity(new Intent(this, ActivityPro.class)); - return; - } - ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(prefs.getBoolean(name, false)); - } - - Object value = prefs.getAll().get(name); - if (value instanceof String && "".equals(value)) - prefs.edit().remove(name).apply(); - - // Dependencies - if ("screen_on".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("whitelist_wifi".equals(name) || - "screen_wifi".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("whitelist_other".equals(name) || - "screen_other".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("whitelist_roaming".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("auto_enable".equals(name)) - getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_auto, prefs.getString(name, "0"))); - - else if ("screen_delay".equals(name)) - getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_delay, prefs.getString(name, "0"))); - - else if ("theme".equals(name) || "dark_theme".equals(name)) - recreate(); - - else if ("subnet".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("tethering".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("lan".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("ip6".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("wifi_homes".equals(name)) { - MultiSelectListPreference pref_wifi_homes = (MultiSelectListPreference) getPreferenceScreen().findPreference(name); - Set ssid = prefs.getStringSet(name, new HashSet()); - if (ssid.size() > 0) - pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, TextUtils.join(", ", ssid))); - else - pref_wifi_homes.setTitle(getString(R.string.setting_wifi_home, "-")); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("use_metered".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("unmetered_2g".equals(name) || - "unmetered_3g".equals(name) || - "unmetered_4g".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("national_roaming".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("eu_roaming".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("disable_on_call".equals(name)) { - if (prefs.getBoolean(name, false)) { - if (checkPermissions(name)) - ServiceSinkhole.reload("changed " + name, this, false); - } else - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("lockdown_wifi".equals(name) || "lockdown_other".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("manage_system".equals(name)) { - boolean manage = prefs.getBoolean(name, false); - if (!manage) - prefs.edit().putBoolean("show_user", true).apply(); - prefs.edit().putBoolean("show_system", manage).apply(); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("log_app".equals(name)) { - Intent ruleset = new Intent(ActivityMain.ACTION_RULES_CHANGED); - LocalBroadcastManager.getInstance(this).sendBroadcast(ruleset); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("notify_access".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("filter".equals(name)) { - // Show dialog - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && prefs.getBoolean(name, false)) { - LayoutInflater inflater = LayoutInflater.from(ActivitySettings.this); - View view = inflater.inflate(R.layout.filter, null, false); - dialogFilter = new AlertDialog.Builder(ActivitySettings.this) - .setView(view) - .setCancelable(false) - .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // Do nothing - } - }) - .setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialogInterface) { - dialogFilter = null; - } - }) - .create(); - dialogFilter.show(); - } else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP && !prefs.getBoolean(name, false)) { - prefs.edit().putBoolean(name, true).apply(); - Toast.makeText(ActivitySettings.this, R.string.msg_filter4, Toast.LENGTH_SHORT).show(); - } - - ((TwoStatePreference) getPreferenceScreen().findPreference(name)).setChecked(prefs.getBoolean(name, false)); - - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("use_hosts".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("vpn4".equals(name)) { - String vpn4 = prefs.getString(name, null); - try { - checkAddress(vpn4, false); - prefs.edit().putString(name, vpn4.trim()).apply(); - } catch (Throwable ex) { - prefs.edit().remove(name).apply(); - ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); - if (!TextUtils.isEmpty(vpn4)) - Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - getPreferenceScreen().findPreference(name).setTitle( - getString(R.string.setting_vpn4, prefs.getString(name, "10.1.10.1"))); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("vpn6".equals(name)) { - String vpn6 = prefs.getString(name, null); - try { - checkAddress(vpn6, false); - prefs.edit().putString(name, vpn6.trim()).apply(); - } catch (Throwable ex) { - prefs.edit().remove(name).apply(); - ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); - if (!TextUtils.isEmpty(vpn6)) - Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - getPreferenceScreen().findPreference(name).setTitle( - getString(R.string.setting_vpn6, prefs.getString(name, "fd00:1:fd00:1:fd00:1:fd00:1"))); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("dns".equals(name) || "dns2".equals(name)) { - String dns = prefs.getString(name, null); - try { - checkAddress(dns, true); - prefs.edit().putString(name, dns.trim()).apply(); - } catch (Throwable ex) { - prefs.edit().remove(name).apply(); - ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); - if (!TextUtils.isEmpty(dns)) - Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - getPreferenceScreen().findPreference(name).setTitle( - getString(R.string.setting_dns, prefs.getString(name, "-"))); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("validate".equals(name)) { - String host = prefs.getString(name, "www.google.com"); - try { - checkDomain(host); - prefs.edit().putString(name, host.trim()).apply(); - } catch (Throwable ex) { - prefs.edit().remove(name).apply(); - ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); - if (!TextUtils.isEmpty(host)) - Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - getPreferenceScreen().findPreference(name).setTitle( - getString(R.string.setting_validate, prefs.getString(name, "www.google.com"))); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("ttl".equals(name)) - getPreferenceScreen().findPreference(name).setTitle( - getString(R.string.setting_ttl, prefs.getString(name, "259200"))); - - else if ("rcode".equals(name)) { - getPreferenceScreen().findPreference(name).setTitle( - getString(R.string.setting_rcode, prefs.getString(name, "3"))); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("socks5_enabled".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - - else if ("socks5_addr".equals(name)) { - String socks5_addr = prefs.getString(name, null); - try { - if (!TextUtils.isEmpty(socks5_addr) && !Util.isNumericAddress(socks5_addr)) - throw new IllegalArgumentException("Bad address"); - } catch (Throwable ex) { - prefs.edit().remove(name).apply(); - ((EditTextPreference) getPreferenceScreen().findPreference(name)).setText(null); - if (!TextUtils.isEmpty(socks5_addr)) - Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - getPreferenceScreen().findPreference(name).setTitle( - getString(R.string.setting_socks5_addr, prefs.getString(name, "-"))); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("socks5_port".equals(name)) { - getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_port, prefs.getString(name, "-"))); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("socks5_username".equals(name)) { - getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_username, prefs.getString(name, "-"))); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("socks5_password".equals(name)) { - getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_socks5_password, TextUtils.isEmpty(prefs.getString(name, "")) ? "-" : "*****")); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("pcap_record_size".equals(name) || "pcap_file_size".equals(name)) { - if ("pcap_record_size".equals(name)) - getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_pcap_record_size, prefs.getString(name, "64"))); - else - getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_pcap_file_size, prefs.getString(name, "2"))); - - ServiceSinkhole.setPcap(false, this); - - File pcap_file = new File(getDir("data", MODE_PRIVATE), "netguard.pcap"); - if (pcap_file.exists() && !pcap_file.delete()) - Log.w(TAG, "Delete PCAP failed"); - - if (prefs.getBoolean("pcap", false)) - ServiceSinkhole.setPcap(true, this); - - } else if ("watchdog".equals(name)) { - getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_watchdog, prefs.getString(name, "0"))); - ServiceSinkhole.reload("changed " + name, this, false); - - } else if ("show_stats".equals(name)) - ServiceSinkhole.reloadStats("changed " + name, this); - - else if ("stats_frequency".equals(name)) - getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_frequency, prefs.getString(name, "1000"))); - - else if ("stats_samples".equals(name)) - getPreferenceScreen().findPreference(name).setTitle(getString(R.string.setting_stats_samples, prefs.getString(name, "90"))); - - else if ("hosts_url".equals(name)) - getPreferenceScreen().findPreference(name).setSummary(prefs.getString(name, BuildConfig.HOSTS_FILE_URI)); - - else if ("loglevel".equals(name)) - ServiceSinkhole.reload("changed " + name, this, false); - } - - @TargetApi(Build.VERSION_CODES.M) - private boolean checkPermissions(String name) { - PreferenceScreen screen = getPreferenceScreen(); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - - // Check if permission was revoked - if ((name == null || "disable_on_call".equals(name)) && prefs.getBoolean("disable_on_call", false)) - if (!Util.hasPhoneStatePermission(this)) { - prefs.edit().putBoolean("disable_on_call", false).apply(); - ((TwoStatePreference) screen.findPreference("disable_on_call")).setChecked(false); - - requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_CALL); - - if (name != null) - return false; - } - - return true; - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - PreferenceScreen screen = getPreferenceScreen(); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - - boolean granted = (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED); - - if (requestCode == REQUEST_CALL) { - prefs.edit().putBoolean("disable_on_call", granted).apply(); - ((TwoStatePreference) screen.findPreference("disable_on_call")).setChecked(granted); - } - - if (granted) - ServiceSinkhole.reload("permission granted", this, false); - } - - private void checkAddress(String address, boolean allow_local) throws IllegalArgumentException, UnknownHostException { - if (address != null) - address = address.trim(); - if (TextUtils.isEmpty(address)) - throw new IllegalArgumentException("Bad address"); - if (!Util.isNumericAddress(address)) - throw new IllegalArgumentException("Bad address"); - if (!allow_local) { - InetAddress iaddr = InetAddress.getByName(address); - if (iaddr.isLoopbackAddress() || iaddr.isAnyLocalAddress()) - throw new IllegalArgumentException("Bad address"); - } - } - - private void checkDomain(String address) throws IllegalArgumentException, UnknownHostException { - if (address != null) - address = address.trim(); - if (TextUtils.isEmpty(address)) - throw new IllegalArgumentException("Bad address"); - if (Util.isNumericAddress(address)) - throw new IllegalArgumentException("Bad address"); - if (!PatternsCompat.DOMAIN_NAME.matcher(address).matches()) - throw new IllegalArgumentException("Bad address"); - } - - private BroadcastReceiver interactiveStateReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - Util.logExtras(intent); - updateTechnicalInfo(); - } - }; - - private BroadcastReceiver connectivityChangedReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - Util.logExtras(intent); - updateTechnicalInfo(); - } - }; - - private void markPro(Preference pref, String sku) { - if (sku == null || !IAB.isPurchased(sku, this)) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean dark = prefs.getBoolean("dark_theme", false); - SpannableStringBuilder ssb = new SpannableStringBuilder(" " + pref.getTitle()); - ssb.setSpan(new ImageSpan(this, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - pref.setTitle(ssb); - } - } - - private void updateTechnicalInfo() { - PreferenceScreen screen = getPreferenceScreen(); - Preference pref_technical_info = screen.findPreference("technical_info"); - Preference pref_technical_network = screen.findPreference("technical_network"); - - pref_technical_info.setSummary(Util.getGeneralInfo(this)); - pref_technical_network.setSummary(Util.getNetworkInfo(this)); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, final Intent data) { - Log.i(TAG, "onActivityResult request=" + requestCode + " result=" + requestCode + " ok=" + (resultCode == RESULT_OK)); - if (requestCode == REQUEST_EXPORT) { - if (resultCode == RESULT_OK && data != null) - handleExport(data); - - } else if (requestCode == REQUEST_IMPORT) { - if (resultCode == RESULT_OK && data != null) - handleImport(data); - - } else if (requestCode == REQUEST_HOSTS) { - if (resultCode == RESULT_OK && data != null) - handleHosts(data, false); - - } else if (requestCode == REQUEST_HOSTS_APPEND) { - if (resultCode == RESULT_OK && data != null) - handleHosts(data, true); - - } else { - Log.w(TAG, "Unknown activity result request=" + requestCode); - super.onActivityResult(requestCode, resultCode, data); - } - } - - private Intent getIntentCreateExport() { - Intent intent; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - if (Util.isPackageInstalled("org.openintents.filemanager", this)) { - intent = new Intent("org.openintents.action.PICK_DIRECTORY"); - } else { - intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=org.openintents.filemanager")); - } - } else { - intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("*/*"); // text/xml - intent.putExtra(Intent.EXTRA_TITLE, "netguard_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml"); - } - return intent; - } - - private Intent getIntentOpenExport() { - Intent intent; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) - intent = new Intent(Intent.ACTION_GET_CONTENT); - else - intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("*/*"); // text/xml - return intent; - } - - private Intent getIntentOpenHosts() { - Intent intent; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) - intent = new Intent(Intent.ACTION_GET_CONTENT); - else - intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("*/*"); // text/plain - return intent; - } - - private void handleExport(final Intent data) { - new AsyncTask() { - @Override - protected Throwable doInBackground(Object... objects) { - OutputStream out = null; - try { - Uri target = data.getData(); - if (data.hasExtra("org.openintents.extra.DIR_PATH")) - target = Uri.parse(target + "/netguard_" + new SimpleDateFormat("yyyyMMdd").format(new Date().getTime()) + ".xml"); - Log.i(TAG, "Writing URI=" + target); - out = getContentResolver().openOutputStream(target); - xmlExport(out); - return null; - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - return ex; - } finally { - if (out != null) - try { - out.close(); - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - } - - @Override - protected void onPostExecute(Throwable ex) { - if (running) { - if (ex == null) - Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show(); - else - Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void handleHosts(final Intent data, final boolean append) { - new AsyncTask() { - @Override - protected Throwable doInBackground(Object... objects) { - File hosts = new File(getFilesDir(), "hosts.txt"); - - FileOutputStream out = null; - InputStream in = null; - try { - Log.i(TAG, "Reading URI=" + data.getData()); - ContentResolver resolver = getContentResolver(); - String[] streamTypes = resolver.getStreamTypes(data.getData(), "*/*"); - String streamType = (streamTypes == null || streamTypes.length == 0 ? "*/*" : streamTypes[0]); - AssetFileDescriptor descriptor = resolver.openTypedAssetFileDescriptor(data.getData(), streamType, null); - in = descriptor.createInputStream(); - out = new FileOutputStream(hosts, append); - - int len; - long total = 0; - byte[] buf = new byte[4096]; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); - total += len; - } - Log.i(TAG, "Copied bytes=" + total); - - return null; - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - return ex; - } finally { - if (out != null) - try { - out.close(); - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - if (in != null) - try { - in.close(); - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - } - - @Override - protected void onPostExecute(Throwable ex) { - if (running) { - if (ex == null) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ActivitySettings.this); - String last = SimpleDateFormat.getDateTimeInstance().format(new Date().getTime()); - prefs.edit().putString("hosts_last_import", last).apply(); - - if (running) { - getPreferenceScreen().findPreference("hosts_import").setSummary(getString(R.string.msg_import_last, last)); - Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show(); - } - - ServiceSinkhole.reload("hosts import", ActivitySettings.this, false); - } else - Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void handleImport(final Intent data) { - new AsyncTask() { - @Override - protected Throwable doInBackground(Object... objects) { - InputStream in = null; - try { - Log.i(TAG, "Reading URI=" + data.getData()); - ContentResolver resolver = getContentResolver(); - String[] streamTypes = resolver.getStreamTypes(data.getData(), "*/*"); - String streamType = (streamTypes == null || streamTypes.length == 0 ? "*/*" : streamTypes[0]); - AssetFileDescriptor descriptor = resolver.openTypedAssetFileDescriptor(data.getData(), streamType, null); - in = descriptor.createInputStream(); - xmlImport(in); - return null; - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - return ex; - } finally { - if (in != null) - try { - in.close(); - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - } - - @Override - protected void onPostExecute(Throwable ex) { - if (running) { - if (ex == null) { - Toast.makeText(ActivitySettings.this, R.string.msg_completed, Toast.LENGTH_LONG).show(); - ServiceSinkhole.reloadStats("import", ActivitySettings.this); - // Update theme, request permissions - recreate(); - } else - Toast.makeText(ActivitySettings.this, ex.toString(), Toast.LENGTH_LONG).show(); - } - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void xmlExport(OutputStream out) throws IOException { - XmlSerializer serializer = Xml.newSerializer(); - serializer.setOutput(out, "UTF-8"); - serializer.startDocument(null, true); - serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true); - serializer.startTag(null, "netguard"); - - serializer.startTag(null, "application"); - xmlExport(PreferenceManager.getDefaultSharedPreferences(this), serializer); - serializer.endTag(null, "application"); - - serializer.startTag(null, "wifi"); - xmlExport(getSharedPreferences("wifi", Context.MODE_PRIVATE), serializer); - serializer.endTag(null, "wifi"); - - serializer.startTag(null, "mobile"); - xmlExport(getSharedPreferences("other", Context.MODE_PRIVATE), serializer); - serializer.endTag(null, "mobile"); - - serializer.startTag(null, "screen_wifi"); - xmlExport(getSharedPreferences("screen_wifi", Context.MODE_PRIVATE), serializer); - serializer.endTag(null, "screen_wifi"); - - serializer.startTag(null, "screen_other"); - xmlExport(getSharedPreferences("screen_other", Context.MODE_PRIVATE), serializer); - serializer.endTag(null, "screen_other"); - - serializer.startTag(null, "roaming"); - xmlExport(getSharedPreferences("roaming", Context.MODE_PRIVATE), serializer); - serializer.endTag(null, "roaming"); - - serializer.startTag(null, "lockdown"); - xmlExport(getSharedPreferences("lockdown", Context.MODE_PRIVATE), serializer); - serializer.endTag(null, "lockdown"); - - serializer.startTag(null, "apply"); - xmlExport(getSharedPreferences("apply", Context.MODE_PRIVATE), serializer); - serializer.endTag(null, "apply"); - - serializer.startTag(null, "notify"); - xmlExport(getSharedPreferences("notify", Context.MODE_PRIVATE), serializer); - serializer.endTag(null, "notify"); - - serializer.startTag(null, "filter"); - filterExport(serializer); - serializer.endTag(null, "filter"); - - serializer.startTag(null, "forward"); - forwardExport(serializer); - serializer.endTag(null, "forward"); - - serializer.endTag(null, "netguard"); - serializer.endDocument(); - serializer.flush(); - } - - private void xmlExport(SharedPreferences prefs, XmlSerializer serializer) throws IOException { - Map settings = prefs.getAll(); - for (String key : settings.keySet()) { - Object value = settings.get(key); - - if ("imported".equals(key)) - continue; - - if (value instanceof Boolean) { - serializer.startTag(null, "setting"); - serializer.attribute(null, "key", key); - serializer.attribute(null, "type", "boolean"); - serializer.attribute(null, "value", value.toString()); - serializer.endTag(null, "setting"); - - } else if (value instanceof Integer) { - serializer.startTag(null, "setting"); - serializer.attribute(null, "key", key); - serializer.attribute(null, "type", "integer"); - serializer.attribute(null, "value", value.toString()); - serializer.endTag(null, "setting"); - - } else if (value instanceof String) { - serializer.startTag(null, "setting"); - serializer.attribute(null, "key", key); - serializer.attribute(null, "type", "string"); - serializer.attribute(null, "value", value.toString()); - serializer.endTag(null, "setting"); - - } else if (value instanceof Set) { - Set set = (Set) value; - serializer.startTag(null, "setting"); - serializer.attribute(null, "key", key); - serializer.attribute(null, "type", "set"); - serializer.attribute(null, "value", TextUtils.join("\n", set)); - serializer.endTag(null, "setting"); - - } else - Log.e(TAG, "Unknown key=" + key); - } - } - - private void filterExport(XmlSerializer serializer) throws IOException { - try (Cursor cursor = DatabaseHelper.getInstance(this).getAccess()) { - int colUid = cursor.getColumnIndex("uid"); - int colVersion = cursor.getColumnIndex("version"); - int colProtocol = cursor.getColumnIndex("protocol"); - int colDAddr = cursor.getColumnIndex("daddr"); - int colDPort = cursor.getColumnIndex("dport"); - int colTime = cursor.getColumnIndex("time"); - int colBlock = cursor.getColumnIndex("block"); - while (cursor.moveToNext()) - for (String pkg : getPackages(cursor.getInt(colUid))) { - serializer.startTag(null, "rule"); - serializer.attribute(null, "pkg", pkg); - serializer.attribute(null, "version", Integer.toString(cursor.getInt(colVersion))); - serializer.attribute(null, "protocol", Integer.toString(cursor.getInt(colProtocol))); - serializer.attribute(null, "daddr", cursor.getString(colDAddr)); - serializer.attribute(null, "dport", Integer.toString(cursor.getInt(colDPort))); - serializer.attribute(null, "time", Long.toString(cursor.getLong(colTime))); - serializer.attribute(null, "block", Integer.toString(cursor.getInt(colBlock))); - serializer.endTag(null, "rule"); - } - } - } - - private void forwardExport(XmlSerializer serializer) throws IOException { - try (Cursor cursor = DatabaseHelper.getInstance(this).getForwarding()) { - int colProtocol = cursor.getColumnIndex("protocol"); - int colDPort = cursor.getColumnIndex("dport"); - int colRAddr = cursor.getColumnIndex("raddr"); - int colRPort = cursor.getColumnIndex("rport"); - int colRUid = cursor.getColumnIndex("ruid"); - while (cursor.moveToNext()) - for (String pkg : getPackages(cursor.getInt(colRUid))) { - serializer.startTag(null, "port"); - serializer.attribute(null, "pkg", pkg); - serializer.attribute(null, "protocol", Integer.toString(cursor.getInt(colProtocol))); - serializer.attribute(null, "dport", Integer.toString(cursor.getInt(colDPort))); - serializer.attribute(null, "raddr", cursor.getString(colRAddr)); - serializer.attribute(null, "rport", Integer.toString(cursor.getInt(colRPort))); - serializer.endTag(null, "port"); - } - } - } - - private String[] getPackages(int uid) { - if (uid == 0) - return new String[]{"root"}; - else if (uid == 1013) - return new String[]{"mediaserver"}; - else if (uid == 9999) - return new String[]{"nobody"}; - else { - String pkgs[] = getPackageManager().getPackagesForUid(uid); - if (pkgs == null) - return new String[0]; - else - return pkgs; - } - } - - private void xmlImport(InputStream in) throws IOException, SAXException, ParserConfigurationException { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.unregisterOnSharedPreferenceChangeListener(this); - prefs.edit().putBoolean("enabled", false).apply(); - ServiceSinkhole.stop("import", this, false); - - XMLReader reader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); - XmlImportHandler handler = new XmlImportHandler(this); - reader.setContentHandler(handler); - reader.parse(new InputSource(in)); - - xmlImport(handler.application, prefs); - xmlImport(handler.wifi, getSharedPreferences("wifi", Context.MODE_PRIVATE)); - xmlImport(handler.mobile, getSharedPreferences("other", Context.MODE_PRIVATE)); - xmlImport(handler.screen_wifi, getSharedPreferences("screen_wifi", Context.MODE_PRIVATE)); - xmlImport(handler.screen_other, getSharedPreferences("screen_other", Context.MODE_PRIVATE)); - xmlImport(handler.roaming, getSharedPreferences("roaming", Context.MODE_PRIVATE)); - xmlImport(handler.lockdown, getSharedPreferences("lockdown", Context.MODE_PRIVATE)); - xmlImport(handler.apply, getSharedPreferences("apply", Context.MODE_PRIVATE)); - xmlImport(handler.notify, getSharedPreferences("notify", Context.MODE_PRIVATE)); - - // Upgrade imported settings - ReceiverAutostart.upgrade(true, this); - - DatabaseHelper.clearCache(); - - // Refresh UI - prefs.edit().putBoolean("imported", true).apply(); - prefs.registerOnSharedPreferenceChangeListener(this); - } - - private void xmlImport(Map settings, SharedPreferences prefs) { - SharedPreferences.Editor editor = prefs.edit(); - - // Clear existing setting - for (String key : prefs.getAll().keySet()) - if (!"enabled".equals(key)) - editor.remove(key); - - // Apply new settings - for (String key : settings.keySet()) { - Object value = settings.get(key); - if (value instanceof Boolean) - editor.putBoolean(key, (Boolean) value); - else if (value instanceof Integer) - editor.putInt(key, (Integer) value); - else if (value instanceof String) - editor.putString(key, (String) value); - else if (value instanceof Set) - editor.putStringSet(key, (Set) value); - else - Log.e(TAG, "Unknown type=" + value.getClass()); - } - - editor.apply(); - } - - private class XmlImportHandler extends DefaultHandler { - private Context context; - public boolean enabled = false; - public Map application = new HashMap<>(); - public Map wifi = new HashMap<>(); - public Map mobile = new HashMap<>(); - public Map screen_wifi = new HashMap<>(); - public Map screen_other = new HashMap<>(); - public Map roaming = new HashMap<>(); - public Map lockdown = new HashMap<>(); - public Map apply = new HashMap<>(); - public Map notify = new HashMap<>(); - private Map current = null; - - public XmlImportHandler(Context context) { - this.context = context; - } - - @Override - public void startElement(String uri, String localName, String qName, Attributes attributes) { - if (qName.equals("netguard")) - ; // Ignore - - else if (qName.equals("application")) - current = application; - - else if (qName.equals("wifi")) - current = wifi; - - else if (qName.equals("mobile")) - current = mobile; - - else if (qName.equals("screen_wifi")) - current = screen_wifi; - - else if (qName.equals("screen_other")) - current = screen_other; - - else if (qName.equals("roaming")) - current = roaming; - - else if (qName.equals("lockdown")) - current = lockdown; - - else if (qName.equals("apply")) - current = apply; - - else if (qName.equals("notify")) - current = notify; - - else if (qName.equals("filter")) { - current = null; - Log.i(TAG, "Clearing filters"); - DatabaseHelper.getInstance(context).clearAccess(); - - } else if (qName.equals("forward")) { - current = null; - Log.i(TAG, "Clearing forwards"); - DatabaseHelper.getInstance(context).deleteForward(); - - } else if (qName.equals("setting")) { - String key = attributes.getValue("key"); - String type = attributes.getValue("type"); - String value = attributes.getValue("value"); - - if (current == null) - Log.e(TAG, "No current key=" + key); - else { - if ("enabled".equals(key)) - enabled = Boolean.parseBoolean(value); - else { - if (current == application) { - // Pro features - if ("log".equals(key)) { - if (!IAB.isPurchased(ActivityPro.SKU_LOG, context)) - return; - } else if ("theme".equals(key)) { - if (!IAB.isPurchased(ActivityPro.SKU_THEME, context)) - return; - } else if ("show_stats".equals(key)) { - if (!IAB.isPurchased(ActivityPro.SKU_SPEED, context)) - return; - } - - if ("hosts_last_import".equals(key) || "hosts_last_download".equals(key)) - return; - } - - if ("boolean".equals(type)) - current.put(key, Boolean.parseBoolean(value)); - else if ("integer".equals(type)) - current.put(key, Integer.parseInt(value)); - else if ("string".equals(type)) - current.put(key, value); - else if ("set".equals(type)) { - Set set = new HashSet<>(); - if (!TextUtils.isEmpty(value)) - for (String s : value.split("\n")) - set.add(s); - current.put(key, set); - } else - Log.e(TAG, "Unknown type key=" + key); - } - } - - } else if (qName.equals("rule")) { - String pkg = attributes.getValue("pkg"); - - String version = attributes.getValue("version"); - String protocol = attributes.getValue("protocol"); - - Packet packet = new Packet(); - packet.version = (version == null ? 4 : Integer.parseInt(version)); - packet.protocol = (protocol == null ? 6 /* TCP */ : Integer.parseInt(protocol)); - packet.daddr = attributes.getValue("daddr"); - packet.dport = Integer.parseInt(attributes.getValue("dport")); - packet.time = Long.parseLong(attributes.getValue("time")); - - int block = Integer.parseInt(attributes.getValue("block")); - - try { - packet.uid = getUid(pkg); - DatabaseHelper.getInstance(context).updateAccess(packet, null, block); - } catch (PackageManager.NameNotFoundException ex) { - Log.w(TAG, "Package not found pkg=" + pkg); - } - - } else if (qName.equals("port")) { - String pkg = attributes.getValue("pkg"); - int protocol = Integer.parseInt(attributes.getValue("protocol")); - int dport = Integer.parseInt(attributes.getValue("dport")); - String raddr = attributes.getValue("raddr"); - int rport = Integer.parseInt(attributes.getValue("rport")); - - try { - int uid = getUid(pkg); - DatabaseHelper.getInstance(context).addForward(protocol, dport, raddr, rport, uid); - } catch (PackageManager.NameNotFoundException ex) { - Log.w(TAG, "Package not found pkg=" + pkg); - } - - } else - Log.e(TAG, "Unknown element qname=" + qName); - } - - private int getUid(String pkg) throws PackageManager.NameNotFoundException { - if ("root".equals(pkg)) - return 0; - else if ("android.media".equals(pkg)) - return 1013; - else if ("android.multicast".equals(pkg)) - return 1020; - else if ("android.gps".equals(pkg)) - return 1021; - else if ("android.dns".equals(pkg)) - return 1051; - else if ("nobody".equals(pkg)) - return 9999; - else - return getPackageManager().getApplicationInfo(pkg, 0).uid; - } - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterDns.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterDns.java deleted file mode 100644 index 6ddd7e6..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterDns.java +++ /dev/null @@ -1,95 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.Context; -import android.content.SharedPreferences; -import android.database.Cursor; -import android.graphics.Color; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CursorAdapter; -import android.widget.TextView; - -import androidx.preference.PreferenceManager; - -import java.text.SimpleDateFormat; -import java.util.Date; - -public class AdapterDns extends CursorAdapter { - private int colorExpired; - - private int colTime; - private int colQName; - private int colAName; - private int colResource; - private int colTTL; - - public AdapterDns(Context context, Cursor cursor) { - super(context, cursor, 0); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - - if (prefs.getBoolean("dark_theme", false)) - colorExpired = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY), Color.blue(Color.DKGRAY)); - else - colorExpired = Color.argb(128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY), Color.blue(Color.LTGRAY)); - - colTime = cursor.getColumnIndex("time"); - colQName = cursor.getColumnIndex("qname"); - colAName = cursor.getColumnIndex("aname"); - colResource = cursor.getColumnIndex("resource"); - colTTL = cursor.getColumnIndex("ttl"); - } - - @Override - public View newView(Context context, Cursor cursor, ViewGroup parent) { - return LayoutInflater.from(context).inflate(R.layout.dns, parent, false); - } - - @Override - public void bindView(final View view, final Context context, final Cursor cursor) { - // Get values - long time = cursor.getLong(colTime); - String qname = cursor.getString(colQName); - String aname = cursor.getString(colAName); - String resource = cursor.getString(colResource); - int ttl = cursor.getInt(colTTL); - - long now = new Date().getTime(); - boolean expired = (time + ttl < now); - view.setBackgroundColor(expired ? colorExpired : Color.TRANSPARENT); - - // Get views - TextView tvTime = view.findViewById(R.id.tvTime); - TextView tvQName = view.findViewById(R.id.tvQName); - TextView tvAName = view.findViewById(R.id.tvAName); - TextView tvResource = view.findViewById(R.id.tvResource); - TextView tvTTL = view.findViewById(R.id.tvTTL); - - // Set values - tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time)); - tvQName.setText(qname); - tvAName.setText(aname); - tvResource.setText(resource); - tvTTL.setText("+" + Integer.toString(ttl / 1000)); - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterForwarding.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterForwarding.java deleted file mode 100644 index 44ceaa0..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterForwarding.java +++ /dev/null @@ -1,74 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.Context; -import android.database.Cursor; -import android.text.TextUtils; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CursorAdapter; -import android.widget.TextView; - -public class AdapterForwarding extends CursorAdapter { - private int colProtocol; - private int colDPort; - private int colRAddr; - private int colRPort; - private int colRUid; - - public AdapterForwarding(Context context, Cursor cursor) { - super(context, cursor, 0); - colProtocol = cursor.getColumnIndex("protocol"); - colDPort = cursor.getColumnIndex("dport"); - colRAddr = cursor.getColumnIndex("raddr"); - colRPort = cursor.getColumnIndex("rport"); - colRUid = cursor.getColumnIndex("ruid"); - } - - @Override - public View newView(Context context, Cursor cursor, ViewGroup parent) { - return LayoutInflater.from(context).inflate(R.layout.forward, parent, false); - } - - @Override - public void bindView(final View view, final Context context, final Cursor cursor) { - // Get values - int protocol = cursor.getInt(colProtocol); - int dport = cursor.getInt(colDPort); - String raddr = cursor.getString(colRAddr); - int rport = cursor.getInt(colRPort); - int ruid = cursor.getInt(colRUid); - - // Get views - TextView tvProtocol = view.findViewById(R.id.tvProtocol); - TextView tvDPort = view.findViewById(R.id.tvDPort); - TextView tvRAddr = view.findViewById(R.id.tvRAddr); - TextView tvRPort = view.findViewById(R.id.tvRPort); - TextView tvRUid = view.findViewById(R.id.tvRUid); - - tvProtocol.setText(Util.getProtocolName(protocol, 0, false)); - tvDPort.setText(Integer.toString(dport)); - tvRAddr.setText(raddr); - tvRPort.setText(Integer.toString(rport)); - tvRUid.setText(TextUtils.join(", ", Util.getApplicationNames(ruid, context))); - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterRule.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterRule.java deleted file mode 100644 index 6cfe83c..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/AdapterRule.java +++ /dev/null @@ -1,1038 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.annotation.TargetApi; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.PackageManager; -import android.content.res.TypedArray; -import android.database.Cursor; -import android.graphics.Color; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Build; -import android.text.SpannableStringBuilder; -import android.text.Spanned; -import android.text.style.ImageSpan; -import android.util.Log; -import android.util.TypedValue; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.SubMenu; -import android.view.TouchDelegate; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.Button; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.CursorAdapter; -import android.widget.EditText; -import android.widget.Filter; -import android.widget.Filterable; -import android.widget.ImageButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.PopupMenu; -import android.widget.RelativeLayout; -import android.widget.TextView; - -import androidx.appcompat.app.AlertDialog; -import androidx.core.app.NotificationManagerCompat; -import androidx.core.content.ContextCompat; -import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.widget.CompoundButtonCompat; -import androidx.preference.PreferenceManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.bumptech.glide.load.DecodeFormat; -import com.bumptech.glide.request.RequestOptions; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class AdapterRule extends RecyclerView.Adapter implements Filterable { - private static final String TAG = "NetGuard.Adapter"; - - private View anchor; - private LayoutInflater inflater; - private RecyclerView rv; - private int colorText; - private int colorChanged; - private int colorOn; - private int colorOff; - private int colorGrayed; - private int iconSize; - private boolean wifiActive = true; - private boolean otherActive = true; - private boolean live = true; - private List listAll = new ArrayList<>(); - private List listFiltered = new ArrayList<>(); - - private List messaging = Arrays.asList( - "com.discord", - "com.facebook.mlite", - "com.facebook.orca", - "com.instagram.android", - "com.Slack", - "com.skype.raider", - "com.snapchat.android", - "com.whatsapp", - "com.whatsapp.w4b" - ); - - private List download = Arrays.asList( - "com.google.android.youtube" - ); - - public static class ViewHolder extends RecyclerView.ViewHolder { - public View view; - - public LinearLayout llApplication; - public ImageView ivIcon; - public ImageView ivExpander; - public TextView tvName; - - public TextView tvHosts; - - public RelativeLayout rlLockdown; - public ImageView ivLockdown; - - public CheckBox cbWifi; - public ImageView ivScreenWifi; - - public CheckBox cbOther; - public ImageView ivScreenOther; - public TextView tvRoaming; - - public TextView tvRemarkMessaging; - public TextView tvRemarkDownload; - - public LinearLayout llConfiguration; - public TextView tvUid; - public TextView tvPackage; - public TextView tvVersion; - public TextView tvInternet; - public TextView tvDisabled; - - public Button btnRelated; - public ImageButton ibSettings; - public ImageButton ibLaunch; - - public CheckBox cbApply; - - public LinearLayout llScreenWifi; - public ImageView ivWifiLegend; - public CheckBox cbScreenWifi; - - public LinearLayout llScreenOther; - public ImageView ivOtherLegend; - public CheckBox cbScreenOther; - - public CheckBox cbRoaming; - - public CheckBox cbLockdown; - public ImageView ivLockdownLegend; - - public ImageButton btnClear; - - public LinearLayout llFilter; - public ImageView ivLive; - public TextView tvLogging; - public Button btnLogging; - public ListView lvAccess; - public ImageButton btnClearAccess; - public CheckBox cbNotify; - - public EditText romCode; - - public ViewHolder(View itemView) { - super(itemView); - view = itemView; - - llApplication = itemView.findViewById(R.id.llApplication); - ivIcon = itemView.findViewById(R.id.ivIcon); - ivExpander = itemView.findViewById(R.id.ivExpander); - tvName = itemView.findViewById(R.id.tvName); - - tvHosts = itemView.findViewById(R.id.tvHosts); - - rlLockdown = itemView.findViewById(R.id.rlLockdown); - ivLockdown = itemView.findViewById(R.id.ivLockdown); - - cbWifi = itemView.findViewById(R.id.cbWifi); - ivScreenWifi = itemView.findViewById(R.id.ivScreenWifi); - - cbOther = itemView.findViewById(R.id.cbOther); - ivScreenOther = itemView.findViewById(R.id.ivScreenOther); - tvRoaming = itemView.findViewById(R.id.tvRoaming); - - tvRemarkMessaging = itemView.findViewById(R.id.tvRemarkMessaging); - tvRemarkDownload = itemView.findViewById(R.id.tvRemarkDownload); - - llConfiguration = itemView.findViewById(R.id.llConfiguration); - tvUid = itemView.findViewById(R.id.tvUid); - tvPackage = itemView.findViewById(R.id.tvPackage); - tvVersion = itemView.findViewById(R.id.tvVersion); - tvInternet = itemView.findViewById(R.id.tvInternet); - tvDisabled = itemView.findViewById(R.id.tvDisabled); - - btnRelated = itemView.findViewById(R.id.btnRelated); - ibSettings = itemView.findViewById(R.id.ibSettings); - ibLaunch = itemView.findViewById(R.id.ibLaunch); - - cbApply = itemView.findViewById(R.id.cbApply); - - llScreenWifi = itemView.findViewById(R.id.llScreenWifi); - ivWifiLegend = itemView.findViewById(R.id.ivWifiLegend); - cbScreenWifi = itemView.findViewById(R.id.cbScreenWifi); - - llScreenOther = itemView.findViewById(R.id.llScreenOther); - ivOtherLegend = itemView.findViewById(R.id.ivOtherLegend); - cbScreenOther = itemView.findViewById(R.id.cbScreenOther); - - cbRoaming = itemView.findViewById(R.id.cbRoaming); - - cbLockdown = itemView.findViewById(R.id.cbLockdown); - ivLockdownLegend = itemView.findViewById(R.id.ivLockdownLegend); - - btnClear = itemView.findViewById(R.id.btnClear); - - llFilter = itemView.findViewById(R.id.llFilter); - ivLive = itemView.findViewById(R.id.ivLive); - tvLogging = itemView.findViewById(R.id.tvLogging); - btnLogging = itemView.findViewById(R.id.btnLogging); - lvAccess = itemView.findViewById(R.id.lvAccess); - btnClearAccess = itemView.findViewById(R.id.btnClearAccess); - cbNotify = itemView.findViewById(R.id.cbNotify); - - romCode = itemView.findViewById(R.id.romCode); - - final View wifiParent = (View) cbWifi.getParent(); - wifiParent.post(new Runnable() { - public void run() { - Rect rect = new Rect(); - cbWifi.getHitRect(rect); - rect.bottom += rect.top; - rect.right += rect.left; - rect.top = 0; - rect.left = 0; - wifiParent.setTouchDelegate(new TouchDelegate(rect, cbWifi)); - } - }); - - final View otherParent = (View) cbOther.getParent(); - otherParent.post(new Runnable() { - public void run() { - Rect rect = new Rect(); - cbOther.getHitRect(rect); - rect.bottom += rect.top; - rect.right += rect.left; - rect.top = 0; - rect.left = 0; - otherParent.setTouchDelegate(new TouchDelegate(rect, cbOther)); - } - }); - } - } - - public AdapterRule(Context context, View anchor) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - - this.anchor = anchor; - this.inflater = LayoutInflater.from(context); - - if (prefs.getBoolean("dark_theme", false)) - colorChanged = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY), Color.blue(Color.DKGRAY)); - else - colorChanged = Color.argb(128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY), Color.blue(Color.LTGRAY)); - - TypedArray ta = context.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary}); - try { - colorText = ta.getColor(0, 0); - } finally { - ta.recycle(); - } - - TypedValue tv = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.colorOn, tv, true); - colorOn = tv.data; - context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); - colorOff = tv.data; - - colorGrayed = ContextCompat.getColor(context, R.color.colorGrayed); - - TypedValue typedValue = new TypedValue(); - context.getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, typedValue, true); - int height = TypedValue.complexToDimensionPixelSize(typedValue.data, context.getResources().getDisplayMetrics()); - this.iconSize = Math.round(height * context.getResources().getDisplayMetrics().density + 0.5f); - - setHasStableIds(true); - } - - public void set(List listRule) { - listAll = listRule; - listFiltered = new ArrayList<>(); - listFiltered.addAll(listRule); - notifyDataSetChanged(); - } - - public void setWifiActive() { - wifiActive = true; - otherActive = false; - notifyDataSetChanged(); - } - - public void setMobileActive() { - wifiActive = false; - otherActive = true; - notifyDataSetChanged(); - } - - public void setDisconnected() { - wifiActive = false; - otherActive = false; - notifyDataSetChanged(); - } - - public boolean isLive() { - return this.live; - } - - @Override - public void onAttachedToRecyclerView(RecyclerView recyclerView) { - super.onAttachedToRecyclerView(recyclerView); - rv = recyclerView; - } - - @Override - public void onDetachedFromRecyclerView(RecyclerView recyclerView) { - super.onDetachedFromRecyclerView(recyclerView); - rv = null; - } - - @Override - public void onBindViewHolder(final ViewHolder holder, int position) { - final Context context = holder.itemView.getContext(); - - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - final boolean log_app = prefs.getBoolean("log_app", false); - final boolean filter = prefs.getBoolean("filter", false); - final boolean notify_access = prefs.getBoolean("notify_access", false); - - // Get rule - final Rule rule = listFiltered.get(position); - - // Handle expanding/collapsing - holder.llApplication.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - rule.expanded = !rule.expanded; - notifyItemChanged(holder.getAdapterPosition()); - } - }); - - // Show if non default rules - holder.itemView.setBackgroundColor(rule.changed ? colorChanged : Color.TRANSPARENT); - - // Show expand/collapse indicator - holder.ivExpander.setImageLevel(rule.expanded ? 1 : 0); - - // Show application icon - if (rule.icon <= 0) - holder.ivIcon.setImageResource(android.R.drawable.sym_def_app_icon); - else { - Uri uri = Uri.parse("android.resource://" + rule.packageName + "/" + rule.icon); - GlideApp.with(holder.itemView.getContext()) - .applyDefaultRequestOptions(new RequestOptions().format(DecodeFormat.PREFER_RGB_565)) - .load(uri) - //.diskCacheStrategy(DiskCacheStrategy.NONE) - //.skipMemoryCache(true) - .override(iconSize, iconSize) - .into(holder.ivIcon); - } - - // Show application label - holder.tvName.setText(rule.name); - - // Show application state - int color = rule.system ? colorOff : colorText; - if (!rule.internet || !rule.enabled) - color = Color.argb(128, Color.red(color), Color.green(color), Color.blue(color)); - holder.tvName.setTextColor(color); - - holder.tvHosts.setVisibility(rule.hosts > 0 ? View.VISIBLE : View.GONE); - holder.tvHosts.setText(Long.toString(rule.hosts)); - - // Lockdown settings - boolean lockdown = prefs.getBoolean("lockdown", false); - boolean lockdown_wifi = prefs.getBoolean("lockdown_wifi", true); - boolean lockdown_other = prefs.getBoolean("lockdown_other", true); - if ((otherActive && !lockdown_other) || (wifiActive && !lockdown_wifi)) - lockdown = false; - - holder.rlLockdown.setVisibility(lockdown && !rule.lockdown ? View.VISIBLE : View.GONE); - holder.ivLockdown.setEnabled(rule.apply); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrap = DrawableCompat.wrap(holder.ivLockdown.getDrawable()); - DrawableCompat.setTint(wrap, rule.apply ? colorOff : colorGrayed); - } - - boolean screen_on = prefs.getBoolean("screen_on", true); - - // Wi-Fi settings - holder.cbWifi.setEnabled(rule.apply); - holder.cbWifi.setAlpha(wifiActive ? 1 : 0.5f); - holder.cbWifi.setOnCheckedChangeListener(null); - holder.cbWifi.setChecked(rule.wifi_blocked); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrap = DrawableCompat.wrap(CompoundButtonCompat.getButtonDrawable(holder.cbWifi)); - DrawableCompat.setTint(wrap, rule.apply ? (rule.wifi_blocked ? colorOff : colorOn) : colorGrayed); - } - holder.cbWifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { - rule.wifi_blocked = isChecked; - updateRule(context, rule, true, listAll); - } - }); - - holder.ivScreenWifi.setEnabled(rule.apply); - holder.ivScreenWifi.setAlpha(wifiActive ? 1 : 0.5f); - holder.ivScreenWifi.setVisibility(rule.screen_wifi && rule.wifi_blocked ? View.VISIBLE : View.INVISIBLE); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrap = DrawableCompat.wrap(holder.ivScreenWifi.getDrawable()); - DrawableCompat.setTint(wrap, rule.apply ? colorOn : colorGrayed); - } - - // Mobile settings - holder.cbOther.setEnabled(rule.apply); - holder.cbOther.setAlpha(otherActive ? 1 : 0.5f); - holder.cbOther.setOnCheckedChangeListener(null); - holder.cbOther.setChecked(rule.other_blocked); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrap = DrawableCompat.wrap(CompoundButtonCompat.getButtonDrawable(holder.cbOther)); - DrawableCompat.setTint(wrap, rule.apply ? (rule.other_blocked ? colorOff : colorOn) : colorGrayed); - } - holder.cbOther.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { - rule.other_blocked = isChecked; - updateRule(context, rule, true, listAll); - } - }); - - holder.ivScreenOther.setEnabled(rule.apply); - holder.ivScreenOther.setAlpha(otherActive ? 1 : 0.5f); - holder.ivScreenOther.setVisibility(rule.screen_other && rule.other_blocked ? View.VISIBLE : View.INVISIBLE); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrap = DrawableCompat.wrap(holder.ivScreenOther.getDrawable()); - DrawableCompat.setTint(wrap, rule.apply ? colorOn : colorGrayed); - } - - holder.tvRoaming.setTextColor(rule.apply ? colorOff : colorGrayed); - holder.tvRoaming.setAlpha(otherActive ? 1 : 0.5f); - holder.tvRoaming.setVisibility(rule.roaming && (!rule.other_blocked || rule.screen_other) ? View.VISIBLE : View.INVISIBLE); - - holder.tvRemarkMessaging.setVisibility(messaging.contains(rule.packageName) ? View.VISIBLE : View.GONE); - holder.tvRemarkDownload.setVisibility(download.contains(rule.packageName) ? View.VISIBLE : View.GONE); - - // Expanded configuration section - holder.llConfiguration.setVisibility(rule.expanded ? View.VISIBLE : View.GONE); - - // Show application details - holder.tvUid.setText(Integer.toString(rule.uid)); - holder.tvPackage.setText(rule.packageName); - holder.tvVersion.setText(rule.version); - - // Show application state - holder.tvInternet.setVisibility(rule.internet ? View.GONE : View.VISIBLE); - holder.tvDisabled.setVisibility(rule.enabled ? View.GONE : View.VISIBLE); - - // Show related - holder.btnRelated.setVisibility(rule.relateduids ? View.VISIBLE : View.GONE); - holder.btnRelated.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent main = new Intent(context, ActivityMain.class); - main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(rule.uid)); - main.putExtra(ActivityMain.EXTRA_RELATED, true); - context.startActivity(main); - } - }); - - // Launch application settings - if (rule.expanded) { - Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); - intent.setData(Uri.parse("package:" + rule.packageName)); - final Intent settings = (intent.resolveActivity(context.getPackageManager()) == null ? null : intent); - - holder.ibSettings.setVisibility(settings == null ? View.GONE : View.VISIBLE); - holder.ibSettings.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - context.startActivity(settings); - } - }); - } else - holder.ibSettings.setVisibility(View.GONE); - - // Launch application - if (rule.expanded) { - Intent intent = context.getPackageManager().getLaunchIntentForPackage(rule.packageName); - final Intent launch = (intent == null || - intent.resolveActivity(context.getPackageManager()) == null ? null : intent); - - holder.ibLaunch.setVisibility(launch == null ? View.GONE : View.VISIBLE); - holder.ibLaunch.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - context.startActivity(launch); - } - }); - } else - holder.ibLaunch.setVisibility(View.GONE); - - // Apply - holder.cbApply.setEnabled(rule.pkg && filter); - holder.cbApply.setOnCheckedChangeListener(null); - holder.cbApply.setChecked(rule.apply); - holder.cbApply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { - rule.apply = isChecked; - updateRule(context, rule, true, listAll); - } - }); - - // Show Wi-Fi screen on condition - holder.llScreenWifi.setVisibility(screen_on ? View.VISIBLE : View.GONE); - holder.cbScreenWifi.setEnabled(rule.wifi_blocked && rule.apply); - holder.cbScreenWifi.setOnCheckedChangeListener(null); - holder.cbScreenWifi.setChecked(rule.screen_wifi); - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrap = DrawableCompat.wrap(holder.ivWifiLegend.getDrawable()); - DrawableCompat.setTint(wrap, colorOn); - } - - holder.cbScreenWifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - rule.screen_wifi = isChecked; - updateRule(context, rule, true, listAll); - } - }); - - // Show mobile screen on condition - holder.llScreenOther.setVisibility(screen_on ? View.VISIBLE : View.GONE); - holder.cbScreenOther.setEnabled(rule.other_blocked && rule.apply); - holder.cbScreenOther.setOnCheckedChangeListener(null); - holder.cbScreenOther.setChecked(rule.screen_other); - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrap = DrawableCompat.wrap(holder.ivOtherLegend.getDrawable()); - DrawableCompat.setTint(wrap, colorOn); - } - - holder.cbScreenOther.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - rule.screen_other = isChecked; - updateRule(context, rule, true, listAll); - } - }); - - // Show roaming condition - holder.cbRoaming.setEnabled((!rule.other_blocked || rule.screen_other) && rule.apply); - holder.cbRoaming.setOnCheckedChangeListener(null); - holder.cbRoaming.setChecked(rule.roaming); - holder.cbRoaming.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - @TargetApi(Build.VERSION_CODES.M) - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - rule.roaming = isChecked; - updateRule(context, rule, true, listAll); - } - }); - - // Show lockdown - holder.cbLockdown.setEnabled(rule.apply); - holder.cbLockdown.setOnCheckedChangeListener(null); - holder.cbLockdown.setChecked(rule.lockdown); - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrap = DrawableCompat.wrap(holder.ivLockdownLegend.getDrawable()); - DrawableCompat.setTint(wrap, colorOn); - } - - holder.cbLockdown.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - @TargetApi(Build.VERSION_CODES.M) - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - rule.lockdown = isChecked; - updateRule(context, rule, true, listAll); - } - }); - - // Reset rule - holder.btnClear.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Util.areYouSure(view.getContext(), R.string.msg_clear_rules, new Util.DoubtListener() { - @Override - public void onSure() { - holder.cbApply.setChecked(true); - holder.cbWifi.setChecked(rule.wifi_default); - holder.cbOther.setChecked(rule.other_default); - holder.cbScreenWifi.setChecked(rule.screen_wifi_default); - holder.cbScreenOther.setChecked(rule.screen_other_default); - holder.cbRoaming.setChecked(rule.roaming_default); - holder.cbLockdown.setChecked(false); - } - }); - } - }); - - holder.llFilter.setVisibility(Util.canFilter(context) ? View.VISIBLE : View.GONE); - - // Live - holder.ivLive.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - live = !live; - TypedValue tv = new TypedValue(); - view.getContext().getTheme().resolveAttribute(live ? R.attr.iconPause : R.attr.iconPlay, tv, true); - holder.ivLive.setImageResource(tv.resourceId); - if (live) - AdapterRule.this.notifyDataSetChanged(); - } - }); - - // Show logging/filtering is disabled - holder.tvLogging.setText(log_app && filter ? R.string.title_logging_enabled : R.string.title_logging_disabled); - holder.btnLogging.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - LayoutInflater inflater = LayoutInflater.from(context); - View view = inflater.inflate(R.layout.enable, null, false); - - final CheckBox cbLogging = view.findViewById(R.id.cbLogging); - final CheckBox cbFiltering = view.findViewById(R.id.cbFiltering); - final CheckBox cbNotify = view.findViewById(R.id.cbNotify); - TextView tvFilter4 = view.findViewById(R.id.tvFilter4); - - cbLogging.setChecked(log_app); - cbFiltering.setChecked(filter); - cbFiltering.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); - tvFilter4.setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? View.GONE : View.VISIBLE); - cbNotify.setChecked(notify_access); - cbNotify.setEnabled(log_app); - - cbLogging.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("log_app", checked).apply(); - cbNotify.setEnabled(checked); - if (!checked) { - cbNotify.setChecked(false); - prefs.edit().putBoolean("notify_access", false).apply(); - } - ServiceSinkhole.reload("changed notify", context, false); - AdapterRule.this.notifyDataSetChanged(); - } - }); - - cbFiltering.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - if (checked) - cbLogging.setChecked(true); - prefs.edit().putBoolean("filter", checked).apply(); - ServiceSinkhole.reload("changed filter", context, false); - AdapterRule.this.notifyDataSetChanged(); - } - }); - - cbNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("notify_access", checked).apply(); - ServiceSinkhole.reload("changed notify", context, false); - AdapterRule.this.notifyDataSetChanged(); - } - }); - - AlertDialog dialog = new AlertDialog.Builder(context) - .setView(view) - .setCancelable(true) - .create(); - dialog.show(); - } - }); - - // Show access rules - if (rule.expanded) { - // Access the database when expanded only - final AdapterAccess badapter = new AdapterAccess(context, - DatabaseHelper.getInstance(context).getAccess(rule.uid)); - holder.lvAccess.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, final int bposition, long bid) { - PackageManager pm = context.getPackageManager(); - Cursor cursor = (Cursor) badapter.getItem(bposition); - final long id = cursor.getLong(cursor.getColumnIndex("ID")); - final int version = cursor.getInt(cursor.getColumnIndex("version")); - final int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); - final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); - final int dport = cursor.getInt(cursor.getColumnIndex("dport")); - long time = cursor.getLong(cursor.getColumnIndex("time")); - int block = cursor.getInt(cursor.getColumnIndex("block")); - - PopupMenu popup = new PopupMenu(context, anchor); - popup.inflate(R.menu.access); - - popup.getMenu().findItem(R.id.menu_host).setTitle( - Util.getProtocolName(protocol, version, false) + " " + - daddr + (dport > 0 ? "/" + dport : "")); - - SubMenu sub = popup.getMenu().findItem(R.id.menu_host).getSubMenu(); - boolean multiple = false; - Cursor alt = null; - try { - alt = DatabaseHelper.getInstance(context).getAlternateQNames(daddr); - while (alt.moveToNext()) { - multiple = true; - sub.add(Menu.NONE, Menu.NONE, 0, alt.getString(0)).setEnabled(false); - } - } finally { - if (alt != null) - alt.close(); - } - popup.getMenu().findItem(R.id.menu_host).setEnabled(multiple); - - markPro(context, popup.getMenu().findItem(R.id.menu_allow), ActivityPro.SKU_FILTER); - markPro(context, popup.getMenu().findItem(R.id.menu_block), ActivityPro.SKU_FILTER); - - // Whois - final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.dnslytics.com/whois-lookup/" + daddr)); - if (pm.resolveActivity(lookupIP, 0) == null) - popup.getMenu().removeItem(R.id.menu_whois); - else - popup.getMenu().findItem(R.id.menu_whois).setTitle(context.getString(R.string.title_log_whois, daddr)); - - // Lookup port - final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.speedguide.net/port.php?port=" + dport)); - if (dport <= 0 || pm.resolveActivity(lookupPort, 0) == null) - popup.getMenu().removeItem(R.id.menu_port); - else - popup.getMenu().findItem(R.id.menu_port).setTitle(context.getString(R.string.title_log_port, dport)); - - popup.getMenu().findItem(R.id.menu_time).setTitle( - SimpleDateFormat.getDateTimeInstance().format(time)); - - popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem menuItem) { - int menu = menuItem.getItemId(); - boolean result = false; - switch (menu) { - case R.id.menu_whois: - context.startActivity(lookupIP); - result = true; - break; - - case R.id.menu_port: - context.startActivity(lookupPort); - result = true; - break; - - case R.id.menu_allow: - if (IAB.isPurchased(ActivityPro.SKU_FILTER, context)) { - DatabaseHelper.getInstance(context).setAccess(id, 0); - ServiceSinkhole.reload("allow host", context, false); - } else - context.startActivity(new Intent(context, ActivityPro.class)); - result = true; - break; - - case R.id.menu_block: - if (IAB.isPurchased(ActivityPro.SKU_FILTER, context)) { - DatabaseHelper.getInstance(context).setAccess(id, 1); - ServiceSinkhole.reload("block host", context, false); - } else - context.startActivity(new Intent(context, ActivityPro.class)); - result = true; - break; - - case R.id.menu_reset: - DatabaseHelper.getInstance(context).setAccess(id, -1); - ServiceSinkhole.reload("reset host", context, false); - result = true; - break; - - case R.id.menu_copy: - ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("netguard", daddr); - clipboard.setPrimaryClip(clip); - return true; - } - - if (menu == R.id.menu_allow || menu == R.id.menu_block || menu == R.id.menu_reset) - new AsyncTask() { - @Override - protected Long doInBackground(Object... objects) { - return DatabaseHelper.getInstance(context).getHostCount(rule.uid, false); - } - - @Override - protected void onPostExecute(Long hosts) { - rule.hosts = hosts; - notifyDataSetChanged(); - } - }.execute(); - - return result; - } - }); - - if (block == 0) - popup.getMenu().removeItem(R.id.menu_allow); - else if (block == 1) - popup.getMenu().removeItem(R.id.menu_block); - - popup.show(); - } - }); - - holder.lvAccess.setAdapter(badapter); - } else { - holder.lvAccess.setAdapter(null); - holder.lvAccess.setOnItemClickListener(null); - } - - // Clear access log - holder.btnClearAccess.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Util.areYouSure(view.getContext(), R.string.msg_reset_access, new Util.DoubtListener() { - @Override - public void onSure() { - DatabaseHelper.getInstance(context).clearAccess(rule.uid, true); - if (!live) - notifyDataSetChanged(); - if (rv != null) - rv.scrollToPosition(holder.getAdapterPosition()); - } - }); - } - }); - - // Notify on access - holder.cbNotify.setEnabled(prefs.getBoolean("notify_access", false) && rule.apply); - holder.cbNotify.setOnCheckedChangeListener(null); - holder.cbNotify.setChecked(rule.notify); - holder.cbNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { - rule.notify = isChecked; - updateRule(context, rule, true, listAll); - } - }); - } - - @Override - public void onViewRecycled(ViewHolder holder) { - super.onViewRecycled(holder); - - //Context context = holder.itemView.getContext(); - //GlideApp.with(context).clear(holder.ivIcon); - - CursorAdapter adapter = (CursorAdapter) holder.lvAccess.getAdapter(); - if (adapter != null) { - Log.i(TAG, "Closing access cursor"); - adapter.changeCursor(null); - holder.lvAccess.setAdapter(null); - } - } - - private void markPro(Context context, MenuItem menu, String sku) { - if (sku == null || !IAB.isPurchased(sku, context)) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean dark = prefs.getBoolean("dark_theme", false); - SpannableStringBuilder ssb = new SpannableStringBuilder(" " + menu.getTitle()); - ssb.setSpan(new ImageSpan(context, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - menu.setTitle(ssb); - } - } - - private void updateRule(Context context, Rule rule, boolean root, List listAll) { - SharedPreferences wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE); - SharedPreferences other = context.getSharedPreferences("other", Context.MODE_PRIVATE); - SharedPreferences apply = context.getSharedPreferences("apply", Context.MODE_PRIVATE); - SharedPreferences screen_wifi = context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE); - SharedPreferences screen_other = context.getSharedPreferences("screen_other", Context.MODE_PRIVATE); - SharedPreferences roaming = context.getSharedPreferences("roaming", Context.MODE_PRIVATE); - SharedPreferences lockdown = context.getSharedPreferences("lockdown", Context.MODE_PRIVATE); - SharedPreferences notify = context.getSharedPreferences("notify", Context.MODE_PRIVATE); - - if (rule.wifi_blocked == rule.wifi_default) - wifi.edit().remove(rule.packageName).apply(); - else - wifi.edit().putBoolean(rule.packageName, rule.wifi_blocked).apply(); - - if (rule.other_blocked == rule.other_default) - other.edit().remove(rule.packageName).apply(); - else - other.edit().putBoolean(rule.packageName, rule.other_blocked).apply(); - - if (rule.apply) - apply.edit().remove(rule.packageName).apply(); - else - apply.edit().putBoolean(rule.packageName, rule.apply).apply(); - - if (rule.screen_wifi == rule.screen_wifi_default) - screen_wifi.edit().remove(rule.packageName).apply(); - else - screen_wifi.edit().putBoolean(rule.packageName, rule.screen_wifi).apply(); - - if (rule.screen_other == rule.screen_other_default) - screen_other.edit().remove(rule.packageName).apply(); - else - screen_other.edit().putBoolean(rule.packageName, rule.screen_other).apply(); - - if (rule.roaming == rule.roaming_default) - roaming.edit().remove(rule.packageName).apply(); - else - roaming.edit().putBoolean(rule.packageName, rule.roaming).apply(); - - if (rule.lockdown) - lockdown.edit().putBoolean(rule.packageName, rule.lockdown).apply(); - else - lockdown.edit().remove(rule.packageName).apply(); - - if (rule.notify) - notify.edit().remove(rule.packageName).apply(); - else - notify.edit().putBoolean(rule.packageName, rule.notify).apply(); - - rule.updateChanged(context); - Log.i(TAG, "Updated " + rule); - - List listModified = new ArrayList<>(); - for (String pkg : rule.related) { - for (Rule related : listAll) - if (related.packageName.equals(pkg)) { - related.wifi_blocked = rule.wifi_blocked; - related.other_blocked = rule.other_blocked; - related.apply = rule.apply; - related.screen_wifi = rule.screen_wifi; - related.screen_other = rule.screen_other; - related.roaming = rule.roaming; - related.lockdown = rule.lockdown; - related.notify = rule.notify; - listModified.add(related); - } - } - - List listSearch = (root ? new ArrayList<>(listAll) : listAll); - listSearch.remove(rule); - for (Rule modified : listModified) - listSearch.remove(modified); - for (Rule modified : listModified) - updateRule(context, modified, false, listSearch); - - if (root) { - notifyDataSetChanged(); - NotificationManagerCompat.from(context).cancel(rule.uid); - ServiceSinkhole.reload("rule changed", context, false); - } - } - - @Override - public Filter getFilter() { - return new Filter() { - @Override - protected FilterResults performFiltering(CharSequence query) { - List listResult = new ArrayList<>(); - if (query == null) - listResult.addAll(listAll); - else { - query = query.toString().toLowerCase().trim(); - int uid; - try { - uid = Integer.parseInt(query.toString()); - } catch (NumberFormatException ignore) { - uid = -1; - } - for (Rule rule : listAll) - if (rule.uid == uid || - rule.packageName.toLowerCase().contains(query) || - (rule.name != null && rule.name.toLowerCase().contains(query))) - listResult.add(rule); - } - - FilterResults result = new FilterResults(); - result.values = listResult; - result.count = listResult.size(); - return result; - } - - @Override - protected void publishResults(CharSequence query, FilterResults result) { - listFiltered.clear(); - if (result == null) - listFiltered.addAll(listAll); - else { - listFiltered.addAll((List) result.values); - if (listFiltered.size() == 1) - listFiltered.get(0).expanded = true; - } - notifyDataSetChanged(); - } - }; - } - - @Override - public AdapterRule.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { - return new ViewHolder(inflater.inflate(R.layout.rule, parent, false)); - } - - @Override - public long getItemId(int position) { - Rule rule = listFiltered.get(position); - return rule.packageName.hashCode() * 100000L + rule.uid; - } - - @Override - public int getItemCount() { - return listFiltered.size(); - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Allowed.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/Allowed.java deleted file mode 100644 index ca79533..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Allowed.java +++ /dev/null @@ -1,48 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -public class Allowed { - - public String raddr; - public int rport; - public int bypass; - public String sender; - - public Allowed() { - this.raddr = null; - this.rport = 0; - this.bypass = 0; - this.sender = "none"; - } - - public Allowed(String raddr, int rport, int bypass) { - this.raddr = raddr; - this.rport = rport; - this.bypass = bypass; - this.sender = "none"; - } - - @Override - public String toString() { - String line = "allowed obj: " + raddr + " at port: " + rport + " with bypass: " + bypass + ", send ip: " + sender; - return line; - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/DownloadTask.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/DownloadTask.java deleted file mode 100644 index ca74ade..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/DownloadTask.java +++ /dev/null @@ -1,181 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.app.Activity; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.os.AsyncTask; -import android.os.Build; -import android.os.PowerManager; -import android.util.Log; -import android.util.TypedValue; -import android.widget.Toast; - -import androidx.core.app.NotificationCompat; -import androidx.core.app.NotificationManagerCompat; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; - -public class DownloadTask extends AsyncTask { - private static final String TAG = "NetGuard.Download"; - - private Context context; - private URL url; - private File file; - private Listener listener; - private PowerManager.WakeLock wakeLock; - - public interface Listener { - void onCompleted(); - - void onCancelled(); - - void onException(Throwable ex); - } - - public DownloadTask(Activity context, URL url, File file, Listener listener) { - this.context = context; - this.url = url; - this.file = file; - this.listener = listener; - } - - @Override - protected void onPreExecute() { - PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); - wakeLock.acquire(); - showNotification(0); - Toast.makeText(context, context.getString(R.string.msg_downloading, url.toString()), Toast.LENGTH_SHORT).show(); - } - - @Override - protected Object doInBackground(Object... args) { - Log.i(TAG, "Downloading " + url + " into " + file); - - InputStream in = null; - OutputStream out = null; - URLConnection connection = null; - try { - connection = url.openConnection(); - connection.connect(); - - if (connection instanceof HttpURLConnection) { - HttpURLConnection httpConnection = (HttpURLConnection) connection; - if (httpConnection.getResponseCode() != HttpURLConnection.HTTP_OK) - throw new IOException(httpConnection.getResponseCode() + " " + httpConnection.getResponseMessage()); - } - - int contentLength = connection.getContentLength(); - Log.i(TAG, "Content length=" + contentLength); - in = connection.getInputStream(); - out = new FileOutputStream(file); - - long size = 0; - byte buffer[] = new byte[4096]; - int bytes; - while (!isCancelled() && (bytes = in.read(buffer)) != -1) { - out.write(buffer, 0, bytes); - - size += bytes; - if (contentLength > 0) - publishProgress((int) (size * 100 / contentLength)); - } - - Log.i(TAG, "Downloaded size=" + size); - return null; - } catch (Throwable ex) { - return ex; - } finally { - try { - if (out != null) - out.close(); - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - try { - if (in != null) - in.close(); - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - if (connection instanceof HttpURLConnection) - ((HttpURLConnection) connection).disconnect(); - } - } - - @Override - protected void onProgressUpdate(Integer... progress) { - super.onProgressUpdate(progress); - showNotification(progress[0]); - } - - @Override - protected void onCancelled() { - super.onCancelled(); - Log.i(TAG, "Cancelled"); - listener.onCancelled(); - } - - @Override - protected void onPostExecute(Object result) { - wakeLock.release(); - NotificationManagerCompat.from(context).cancel(ServiceSinkhole.NOTIFY_DOWNLOAD); - if (result instanceof Throwable) { - Log.e(TAG, result.toString() + "\n" + Log.getStackTraceString((Throwable) result)); - listener.onException((Throwable) result); - } else - listener.onCompleted(); - } - - private void showNotification(int progress) { - Intent main = new Intent(context, ActivitySettings.class); - PendingIntent pi = PendingIntent.getActivity(context, ServiceSinkhole.NOTIFY_DOWNLOAD, main, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); - - TypedValue tv = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "notify"); - builder.setSmallIcon(R.drawable.ic_file_download_white_24dp) - .setContentTitle(context.getString(R.string.app_name)) - .setContentText(context.getString(R.string.msg_downloading, url.toString())) - .setContentIntent(pi) - .setProgress(100, progress, false) - .setColor(tv.data) - .setOngoing(true) - .setAutoCancel(false); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) - builder.setCategory(NotificationCompat.CATEGORY_STATUS) - .setVisibility(NotificationCompat.VISIBILITY_SECRET); - - NotificationManagerCompat.from(context).notify(ServiceSinkhole.NOTIFY_DOWNLOAD, builder.build()); - } - -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ExpandedListView.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/ExpandedListView.java deleted file mode 100644 index ba3a684..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ExpandedListView.java +++ /dev/null @@ -1,45 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.Context; -import android.util.AttributeSet; -import android.widget.ListView; - -// This requires list view items with equal heights - -public class ExpandedListView extends ListView { - public ExpandedListView(Context context) { - super(context); - } - - public ExpandedListView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public ExpandedListView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 4, MeasureSpec.AT_MOST)); - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Forward.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/Forward.java deleted file mode 100644 index 675d782..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Forward.java +++ /dev/null @@ -1,33 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -public class Forward { - public int protocol; - public int dport; - public String raddr; - public int rport; - public int ruid; - - @Override - public String toString() { - return "protocol=" + protocol + " port " + dport + " to " + raddr + "/" + rport + " uid " + ruid; - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/IPUtil.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/IPUtil.java deleted file mode 100644 index e18170d..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/IPUtil.java +++ /dev/null @@ -1,140 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.util.Log; - -import androidx.annotation.NonNull; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.List; - -public class IPUtil { - private static final String TAG = "NetGuard.IPUtil"; - - public static List toCIDR(String start, String end) throws UnknownHostException { - return toCIDR(InetAddress.getByName(start), InetAddress.getByName(end)); - } - - public static List toCIDR(InetAddress start, InetAddress end) throws UnknownHostException { - List listResult = new ArrayList<>(); - - Log.i(TAG, "toCIDR(" + start.getHostAddress() + "," + end.getHostAddress() + ")"); - - long from = inet2long(start); - long to = inet2long(end); - while (to >= from) { - byte prefix = 32; - while (prefix > 0) { - long mask = prefix2mask(prefix - 1); - if ((from & mask) != from) - break; - prefix--; - } - - byte max = (byte) (32 - Math.floor(Math.log(to - from + 1) / Math.log(2))); - if (prefix < max) - prefix = max; - - listResult.add(new CIDR(long2inet(from), prefix)); - - from += Math.pow(2, (32 - prefix)); - } - - for (CIDR cidr : listResult) - Log.i(TAG, cidr.toString()); - - return listResult; - } - - private static long prefix2mask(int bits) { - return (0xFFFFFFFF00000000L >> bits) & 0xFFFFFFFFL; - } - - private static long inet2long(InetAddress addr) { - long result = 0; - if (addr != null) - for (byte b : addr.getAddress()) - result = result << 8 | (b & 0xFF); - return result; - } - - private static InetAddress long2inet(long addr) { - try { - byte[] b = new byte[4]; - for (int i = b.length - 1; i >= 0; i--) { - b[i] = (byte) (addr & 0xFF); - addr = addr >> 8; - } - return InetAddress.getByAddress(b); - } catch (UnknownHostException ignore) { - return null; - } - } - - public static InetAddress minus1(InetAddress addr) { - return long2inet(inet2long(addr) - 1); - } - - public static InetAddress plus1(InetAddress addr) { - return long2inet(inet2long(addr) + 1); - } - - public static class CIDR implements Comparable { - public InetAddress address; - public int prefix; - - public CIDR(InetAddress address, int prefix) { - this.address = address; - this.prefix = prefix; - } - - public CIDR(String ip, int prefix) { - try { - this.address = InetAddress.getByName(ip); - this.prefix = prefix; - } catch (UnknownHostException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - - public InetAddress getStart() { - return long2inet(inet2long(this.address) & prefix2mask(this.prefix)); - } - - public InetAddress getEnd() { - return long2inet((inet2long(this.address) & prefix2mask(this.prefix)) + (1L << (32 - this.prefix)) - 1); - } - - @Override - public String toString() { - return address.getHostAddress() + "/" + prefix + "=" + getStart().getHostAddress() + "..." + getEnd().getHostAddress(); - } - - @Override - public int compareTo(@NonNull CIDR other) { - Long lcidr = IPUtil.inet2long(this.address); - Long lother = IPUtil.inet2long(other.address); - return lcidr.compareTo(lother); - } - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Packet.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/Packet.java deleted file mode 100644 index 5460add..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Packet.java +++ /dev/null @@ -1,42 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -public class Packet { - public long time; - public int version; - public int protocol; - public String flags; - public String saddr; - public int sport; - public String daddr; - public int dport; - public String data; - public int uid; - public boolean allowed; - - public Packet() { - } - - @Override - public String toString() { - return "uid=" + uid + " v" + version + " p" + protocol + " " + daddr + "/" + dport; - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ResourceRecord.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/ResourceRecord.java deleted file mode 100644 index 0d689d1..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ResourceRecord.java +++ /dev/null @@ -1,47 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class ResourceRecord { - public long Time; - public String QName; - public String AName; - public String Resource; - public int TTL; - - private static DateFormat formatter = SimpleDateFormat.getDateTimeInstance(); - - public ResourceRecord() { - } - - @Override - public String toString() { - return formatter.format(new Date(Time).getTime()) + - " Q " + QName + - " A " + AName + - " R " + Resource + - " TTL " + TTL + - " " + formatter.format(new Date(Time + TTL * 1000L).getTime()); - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileFilter.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileFilter.java deleted file mode 100644 index 3ffd0d4..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileFilter.java +++ /dev/null @@ -1,81 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - - -import android.annotation.TargetApi; -import android.content.SharedPreferences; -import android.graphics.drawable.Icon; -import android.os.Build; -import android.service.quicksettings.Tile; -import android.service.quicksettings.TileService; -import android.util.Log; -import android.widget.Toast; - -import androidx.preference.PreferenceManager; - -@TargetApi(Build.VERSION_CODES.N) -public class ServiceTileFilter extends TileService implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.TileFilter"; - - public void onStartListening() { - Log.i(TAG, "Start listening"); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.registerOnSharedPreferenceChangeListener(this); - update(); - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - if ("filter".equals(key)) - update(); - } - - private void update() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean filter = prefs.getBoolean("filter", false); - Tile tile = getQsTile(); - if (tile != null) { - tile.setState(filter ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); - tile.setIcon(Icon.createWithResource(this, filter ? R.drawable.ic_filter_list_white_24dp : R.drawable.ic_filter_list_white_24dp_60)); - tile.updateTile(); - } - } - - public void onStopListening() { - Log.i(TAG, "Stop listening"); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.unregisterOnSharedPreferenceChangeListener(this); - } - - public void onClick() { - Log.i(TAG, "Click"); - - if (Util.canFilter(this)) { - if (IAB.isPurchased(ActivityPro.SKU_FILTER, this)) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.edit().putBoolean("filter", !prefs.getBoolean("filter", false)).apply(); - ServiceSinkhole.reload("tile", this, false); - } else - Toast.makeText(this, R.string.title_pro_feature, Toast.LENGTH_SHORT).show(); - } else - Toast.makeText(this, R.string.msg_unavailable, Toast.LENGTH_SHORT).show(); - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileMain.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileMain.java deleted file mode 100644 index 655819f..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/ServiceTileMain.java +++ /dev/null @@ -1,103 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - - -import android.annotation.TargetApi; -import android.app.AlarmManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.graphics.drawable.Icon; -import android.os.Build; -import android.service.quicksettings.Tile; -import android.service.quicksettings.TileService; -import android.util.Log; - -import androidx.preference.PreferenceManager; - -import java.util.Date; - -@TargetApi(Build.VERSION_CODES.N) -public class ServiceTileMain extends TileService implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.TileMain"; - - public void onStartListening() { - Log.i(TAG, "Start listening"); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.registerOnSharedPreferenceChangeListener(this); - update(); - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - if ("enabled".equals(key)) - update(); - } - - private void update() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean enabled = prefs.getBoolean("enabled", false); - Tile tile = getQsTile(); - if (tile != null) { - tile.setState(enabled ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); - tile.setIcon(Icon.createWithResource(this, enabled ? R.drawable.ic_security_white_24dp : R.drawable.ic_security_white_24dp_60)); - tile.updateTile(); - } - } - - public void onStopListening() { - Log.i(TAG, "Stop listening"); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.unregisterOnSharedPreferenceChangeListener(this); - } - - public void onClick() { - Log.i(TAG, "Click"); - - // Cancel set alarm - AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); - Intent intent = new Intent(WidgetAdmin.INTENT_ON); - intent.setPackage(getPackageName()); - PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); - am.cancel(pi); - - // Check state - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean enabled = !prefs.getBoolean("enabled", false); - prefs.edit().putBoolean("enabled", enabled).apply(); - if (enabled) - ServiceSinkhole.start("tile", this); - else { - ServiceSinkhole.stop("tile", this, false); - - // Auto enable - int auto = Integer.parseInt(prefs.getString("auto_enable", "0")); - if (auto > 0) { - Log.i(TAG, "Scheduling enabled after minutes=" + auto); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) - am.set(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi); - else - am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi); - } - } - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/SwitchPreference.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/SwitchPreference.java deleted file mode 100644 index c8192c6..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/SwitchPreference.java +++ /dev/null @@ -1,39 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.Context; -import android.util.AttributeSet; - -// https://code.google.com/p/android/issues/detail?id=26194 - -public class SwitchPreference extends android.preference.SwitchPreference { - public SwitchPreference(Context context) { - this(context, null); - } - - public SwitchPreference(Context context, AttributeSet attrs) { - this(context, attrs, android.R.attr.switchPreferenceStyle); - } - - public SwitchPreference(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Usage.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/Usage.java deleted file mode 100644 index ccfcb7e..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Usage.java +++ /dev/null @@ -1,46 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class Usage { - public long Time; - public int Version; - public int Protocol; - public String DAddr; - public int DPort; - public int Uid; - public long Sent; - public long Received; - - private static DateFormat formatter = SimpleDateFormat.getDateTimeInstance(); - - @Override - public String toString() { - return formatter.format(new Date(Time).getTime()) + - " v" + Version + " p" + Protocol + - " " + DAddr + "/" + DPort + - " uid " + Uid + - " out " + Sent + " in " + Received; - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Version.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/Version.java deleted file mode 100644 index 7d79191..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/Version.java +++ /dev/null @@ -1,50 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -public class Version implements Comparable { - - private String version; - - public Version(String version) { - this.version = version.replace("-beta", ""); - } - - @Override - public int compareTo(Version other) { - String[] lhs = this.version.split("\\."); - String[] rhs = other.version.split("\\."); - int length = Math.max(lhs.length, rhs.length); - for (int i = 0; i < length; i++) { - int vLhs = (i < lhs.length ? Integer.parseInt(lhs[i]) : 0); - int vRhs = (i < rhs.length ? Integer.parseInt(rhs[i]) : 0); - if (vLhs < vRhs) - return -1; - if (vLhs > vRhs) - return 1; - } - return 0; - } - - @Override - public String toString() { - return version; - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/WidgetAdmin.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/WidgetAdmin.java deleted file mode 100644 index 02b4c98..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/WidgetAdmin.java +++ /dev/null @@ -1,99 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.app.AlarmManager; -import android.app.PendingIntent; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Build; -import android.os.VibrationEffect; -import android.os.Vibrator; -import android.util.Log; - -import androidx.preference.PreferenceManager; - -import java.util.Date; - -public class WidgetAdmin extends ReceiverAutostart { - private static final String TAG = "NetGuard.Widget"; - - public static final String INTENT_ON = "eu.faircode.netguard.ON"; - public static final String INTENT_OFF = "eu.faircode.netguard.OFF"; - - public static final String INTENT_LOCKDOWN_ON = "eu.faircode.netguard.LOCKDOWN_ON"; - public static final String INTENT_LOCKDOWN_OFF = "eu.faircode.netguard.LOCKDOWN_OFF"; - - @Override - public void onReceive(Context context, Intent intent) { - super.onReceive(context, intent); - - Log.i(TAG, "Received " + intent); - Util.logExtras(intent); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - - // Cancel set alarm - AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); - Intent i = new Intent(INTENT_ON); - i.setPackage(context.getPackageName()); - PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); - if (INTENT_ON.equals(intent.getAction()) || INTENT_OFF.equals(intent.getAction())) - am.cancel(pi); - - // Vibrate - Vibrator vs = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); - if (vs.hasVibrator()) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - vs.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE)); - else - vs.vibrate(50); - - try { - if (INTENT_ON.equals(intent.getAction()) || INTENT_OFF.equals(intent.getAction())) { - boolean enabled = INTENT_ON.equals(intent.getAction()); - prefs.edit().putBoolean("enabled", enabled).apply(); - if (enabled) - ServiceSinkhole.start("widget", context); - else - ServiceSinkhole.stop("widget", context, false); - - // Auto enable - int auto = Integer.parseInt(prefs.getString("auto_enable", "0")); - if (!enabled && auto > 0) { - Log.i(TAG, "Scheduling enabled after minutes=" + auto); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) - am.set(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi); - else - am.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, new Date().getTime() + auto * 60 * 1000L, pi); - } - - } else if (INTENT_LOCKDOWN_ON.equals(intent.getAction()) || INTENT_LOCKDOWN_OFF.equals(intent.getAction())) { - boolean lockdown = INTENT_LOCKDOWN_ON.equals(intent.getAction()); - prefs.edit().putBoolean("lockdown", lockdown).apply(); - ServiceSinkhole.reload("widget", context, false); - WidgetLockdown.updateWidgets(context); - } - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } -} diff --git a/NetworkGenie/app/src/main/java/eu/faircode/netguard/WidgetLockdown.java b/NetworkGenie/app/src/main/java/eu/faircode/netguard/WidgetLockdown.java deleted file mode 100644 index a35c01c..0000000 --- a/NetworkGenie/app/src/main/java/eu/faircode/netguard/WidgetLockdown.java +++ /dev/null @@ -1,70 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.app.PendingIntent; -import android.appwidget.AppWidgetManager; -import android.appwidget.AppWidgetProvider; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.util.Log; -import android.widget.RemoteViews; - -import androidx.preference.PreferenceManager; - -public class WidgetLockdown extends AppWidgetProvider { - private static final String TAG = "NetGuard.WidgetLock"; - - @Override - public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { - update(appWidgetIds, appWidgetManager, context); - } - - private static void update(int[] appWidgetIds, AppWidgetManager appWidgetManager, Context context) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean lockdown = prefs.getBoolean("lockdown", false); - - try { - try { - Intent intent = new Intent(lockdown ? WidgetAdmin.INTENT_LOCKDOWN_OFF : WidgetAdmin.INTENT_LOCKDOWN_ON); - intent.setPackage(context.getPackageName()); - PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); - for (int id : appWidgetIds) { - RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widgetlockdown); - views.setOnClickPendingIntent(R.id.ivEnabled, pi); - views.setImageViewResource(R.id.ivEnabled, lockdown ? R.drawable.ic_lock_outline_white_24dp : R.drawable.ic_lock_open_white_24dp); - appWidgetManager.updateAppWidget(id, views); - } - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - - public static void updateWidgets(Context context) { - AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); - int appWidgetIds[] = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, WidgetLockdown.class)); - update(appWidgetIds, appWidgetManager, context); - } -} diff --git a/NetworkGenie/app/src/main/main/AndroidManifest.xml b/NetworkGenie/app/src/main/main/AndroidManifest.xml deleted file mode 100644 index 6682150..0000000 --- a/NetworkGenie/app/src/main/main/AndroidManifest.xml +++ /dev/null @@ -1,287 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/NetworkGenie/app/src/main/main/aidl/com/android/vending/billing/IInAppBillingService.aidl b/NetworkGenie/app/src/main/main/aidl/com/android/vending/billing/IInAppBillingService.aidl deleted file mode 100644 index 2a492f7..0000000 --- a/NetworkGenie/app/src/main/main/aidl/com/android/vending/billing/IInAppBillingService.aidl +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2012 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.vending.billing; - -import android.os.Bundle; - -/** - * InAppBillingService is the service that provides in-app billing version 3 and beyond. - * This service provides the following features: - * 1. Provides a new API to get details of in-app items published for the app including - * price, type, title and description. - * 2. The purchase flow is synchronous and purchase information is available immediately - * after it completes. - * 3. Purchase information of in-app purchases is maintained within the Google Play system - * till the purchase is consumed. - * 4. An API to consume a purchase of an inapp item. All purchases of one-time - * in-app items are consumable and thereafter can be purchased again. - * 5. An API to get current purchases of the user immediately. This will not contain any - * consumed purchases. - * - * All calls will give a response code with the following possible values - * RESULT_OK = 0 - success - * RESULT_USER_CANCELED = 1 - user pressed back or canceled a dialog - * RESULT_BILLING_UNAVAILABLE = 3 - this billing API version is not supported for the type requested - * RESULT_ITEM_UNAVAILABLE = 4 - requested SKU is not available for purchase - * RESULT_DEVELOPER_ERROR = 5 - invalid arguments provided to the API - * RESULT_ERROR = 6 - Fatal error during the API action - * RESULT_ITEM_ALREADY_OWNED = 7 - Failure to purchase since item is already owned - * RESULT_ITEM_NOT_OWNED = 8 - Failure to consume since item is not owned - */ -interface IInAppBillingService { - /** - * Checks support for the requested billing API version, package and in-app type. - * Minimum API version supported by this interface is 3. - * @param apiVersion the billing version which the app is using - * @param packageName the package name of the calling app - * @param type type of the in-app item being purchased "inapp" for one-time purchases - * and "subs" for subscription. - * @return RESULT_OK(0) on success, corresponding result code on failures - */ - int isBillingSupported(int apiVersion, String packageName, String type); - - /** - * Provides details of a list of SKUs - * Given a list of SKUs of a valid type in the skusBundle, this returns a bundle - * with a list JSON strings containing the productId, price, title and description. - * This API can be called with a maximum of 20 SKUs. - * @param apiVersion billing API version that the Third-party is using - * @param packageName the package name of the calling app - * @param skusBundle bundle containing a StringArrayList of SKUs with key "ITEM_ID_LIST" - * @return Bundle containing the following key-value pairs - * "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on - * failure as listed above. - * "DETAILS_LIST" with a StringArrayList containing purchase information - * in JSON format similar to: - * '{ "productId" : "exampleSku", "type" : "inapp", "price" : "$5.00", - * "title : "Example Title", "description" : "This is an example description" }' - */ - Bundle getSkuDetails(int apiVersion, String packageName, String type, in Bundle skusBundle); - - /** - * Returns a pending intent to launch the purchase flow for an in-app item by providing a SKU, - * the type, a unique purchase token and an optional developer payload. - * @param apiVersion billing API version that the app is using - * @param packageName package name of the calling app - * @param sku the SKU of the in-app item as published in the developer console - * @param type the type of the in-app item ("inapp" for one-time purchases - * and "subs" for subscription). - * @param developerPayload optional argument to be sent back with the purchase information - * @return Bundle containing the following key-value pairs - * "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on - * failure as listed above. - * "BUY_INTENT" - PendingIntent to start the purchase flow - * - * The Pending intent should be launched with startIntentSenderForResult. When purchase flow - * has completed, the onActivityResult() will give a resultCode of OK or CANCELED. - * If the purchase is successful, the result data will contain the following key-value pairs - * "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on - * failure as listed above. - * "INAPP_PURCHASE_DATA" - String in JSON format similar to - * '{"orderId":"12999763169054705758.1371079406387615", - * "packageName":"com.example.app", - * "productId":"exampleSku", - * "purchaseTime":1345678900000, - * "purchaseToken" : "122333444455555", - * "developerPayload":"example developer payload" }' - * "INAPP_DATA_SIGNATURE" - String containing the signature of the purchase data that - * was signed with the private key of the developer - * TODO: change this to app-specific keys. - */ - Bundle getBuyIntent(int apiVersion, String packageName, String sku, String type, - String developerPayload); - - /** - * Returns the current SKUs owned by the user of the type and package name specified along with - * purchase information and a signature of the data to be validated. - * This will return all SKUs that have been purchased in V3 and managed items purchased using - * V1 and V2 that have not been consumed. - * @param apiVersion billing API version that the app is using - * @param packageName package name of the calling app - * @param type the type of the in-app items being requested - * ("inapp" for one-time purchases and "subs" for subscription). - * @param continuationToken to be set as null for the first call, if the number of owned - * skus are too many, a continuationToken is returned in the response bundle. - * This method can be called again with the continuation token to get the next set of - * owned skus. - * @return Bundle containing the following key-value pairs - * "RESPONSE_CODE" with int value, RESULT_OK(0) if success, other response codes on - * failure as listed above. - * "INAPP_PURCHASE_ITEM_LIST" - StringArrayList containing the list of SKUs - * "INAPP_PURCHASE_DATA_LIST" - StringArrayList containing the purchase information - * "INAPP_DATA_SIGNATURE_LIST"- StringArrayList containing the signatures - * of the purchase information - * "INAPP_CONTINUATION_TOKEN" - String containing a continuation token for the - * next set of in-app purchases. Only set if the - * user has more owned skus than the current list. - */ - Bundle getPurchases(int apiVersion, String packageName, String type, String continuationToken); - - /** - * Consume the last purchase of the given SKU. This will result in this item being removed - * from all subsequent responses to getPurchases() and allow re-purchase of this item. - * @param apiVersion billing API version that the app is using - * @param packageName package name of the calling app - * @param purchaseToken token in the purchase information JSON that identifies the purchase - * to be consumed - * @return 0 if consumption succeeded. Appropriate error values for failures. - */ - int consumePurchase(int apiVersion, String packageName, String purchaseToken); -} diff --git a/NetworkGenie/app/src/main/main/ic_launcher-web.png b/NetworkGenie/app/src/main/main/ic_launcher-web.png deleted file mode 100644 index 68fe670..0000000 Binary files a/NetworkGenie/app/src/main/main/ic_launcher-web.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/ic_launcher_foreground.xcf b/NetworkGenie/app/src/main/main/ic_launcher_foreground.xcf deleted file mode 100644 index 342fd91..0000000 Binary files a/NetworkGenie/app/src/main/main/ic_launcher_foreground.xcf and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/ic_launcher_round-web.png b/NetworkGenie/app/src/main/main/ic_launcher_round-web.png deleted file mode 100644 index 8e09478..0000000 Binary files a/NetworkGenie/app/src/main/main/ic_launcher_round-web.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/java/assets/log.txt b/NetworkGenie/app/src/main/main/java/assets/log.txt deleted file mode 100644 index 747ec28..0000000 --- a/NetworkGenie/app/src/main/main/java/assets/log.txt +++ /dev/null @@ -1,3 +0,0 @@ -blah -blah -blah diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityForwardApproval.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityForwardApproval.java deleted file mode 100644 index e269fe4..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityForwardApproval.java +++ /dev/null @@ -1,130 +0,0 @@ -package eu.faircode.netguard; - - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.app.Activity; -import android.os.Bundle; -import android.text.TextUtils; -import android.util.Log; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; - -import java.net.InetAddress; - -public class ActivityForwardApproval extends Activity { - private static final String TAG = "NetGuard.Forward"; - private static final String ACTION_START_PORT_FORWARD = "eu.faircode.netguard.START_PORT_FORWARD"; - private static final String ACTION_STOP_PORT_FORWARD = "eu.faircode.netguard.STOP_PORT_FORWARD"; - - static { - try { - System.loadLibrary("netguard"); - } catch (UnsatisfiedLinkError ignored) { - System.exit(1); - } - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.forwardapproval); - - final int protocol = getIntent().getIntExtra("protocol", 0); - final int dport = getIntent().getIntExtra("dport", 0); - String addr = getIntent().getStringExtra("raddr"); - final int rport = getIntent().getIntExtra("rport", 0); - final int ruid = getIntent().getIntExtra("ruid", 0); - final String raddr = (addr == null ? "127.0.0.1" : addr); - - try { - InetAddress iraddr = InetAddress.getByName(raddr); - if (rport < 1024 && (iraddr.isLoopbackAddress() || iraddr.isAnyLocalAddress())) - throw new IllegalArgumentException("Port forwarding to privileged port on local address not possible"); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - finish(); - } - - String pname; - if (protocol == 6) - pname = getString(R.string.menu_protocol_tcp); - else if (protocol == 17) - pname = getString(R.string.menu_protocol_udp); - else - pname = Integer.toString(protocol); - - TextView tvForward = findViewById(R.id.tvForward); - if (ACTION_START_PORT_FORWARD.equals(getIntent().getAction())) - tvForward.setText(getString(R.string.msg_start_forward, - pname, dport, raddr, rport, - TextUtils.join(", ", Util.getApplicationNames(ruid, this)))); - else - tvForward.setText(getString(R.string.msg_stop_forward, pname, dport)); - - Button btnOk = findViewById(R.id.btnOk); - Button btnCancel = findViewById(R.id.btnCancel); - - btnOk.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (ACTION_START_PORT_FORWARD.equals(getIntent().getAction())) { -/* -am start -a eu.faircode.netguard.START_PORT_FORWARD \ --n eu.faircode.netguard/eu.faircode.netguard.ActivityForwardApproval \ ---ei protocol 17 \ ---ei dport 53 \ ---es raddr 8.8.4.4 \ ---ei rport 53 \ ---ei ruid 9999 \ ---user 0 -*/ - Log.i(TAG, "Start forwarding protocol " + protocol + " port " + dport + " to " + raddr + "/" + rport + " uid " + ruid); - DatabaseHelper dh = DatabaseHelper.getInstance(ActivityForwardApproval.this); - dh.deleteForward(protocol, dport); - dh.addForward(protocol, dport, raddr, rport, ruid); - - } else if (ACTION_STOP_PORT_FORWARD.equals(getIntent().getAction())) { -/* -am start -a eu.faircode.netguard.STOP_PORT_FORWARD \ --n eu.faircode.netguard/eu.faircode.netguard.ActivityForwardApproval \ ---ei protocol 17 \ ---ei dport 53 \ ---user 0 -*/ - Log.i(TAG, "Stop forwarding protocol " + protocol + " port " + dport); - DatabaseHelper.getInstance(ActivityForwardApproval.this).deleteForward(protocol, dport); - } - - ServiceSinkhole.reload("forwarding", ActivityForwardApproval.this, false); - - finish(); - } - }); - - btnCancel.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - finish(); - } - }); - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityMain.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityMain.java deleted file mode 100644 index 948e5cd..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityMain.java +++ /dev/null @@ -1,1304 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.content.pm.PackageManager; -import android.content.res.Configuration; -import android.graphics.Color; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.net.VpnService; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.provider.Settings; -import android.text.SpannableString; -import android.text.SpannableStringBuilder; -import android.text.Spanned; -import android.text.TextUtils; -import android.text.method.LinkMovementMethod; -import android.text.style.ImageSpan; -import android.text.style.UnderlineSpan; -import android.util.Log; -import android.util.TypedValue; -import android.view.Gravity; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.widget.Button; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.SearchView; -import androidx.appcompat.widget.SwitchCompat; -import androidx.core.graphics.drawable.DrawableCompat; -import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import androidx.preference.PreferenceManager; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; - -import java.util.List; - -public class ActivityMain extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.Main"; - - private boolean running = false; - private ImageView ivIcon; - private ImageView ivQueue; - private SwitchCompat swEnabled; - private ImageView ivMetered; - private SwipeRefreshLayout swipeRefresh; - private AdapterRule adapter = null; - private MenuItem menuSearch = null; - private AlertDialog dialogFirst = null; - private AlertDialog dialogVpn = null; - private AlertDialog dialogDoze = null; - private AlertDialog dialogLegend = null; - private AlertDialog dialogAbout = null; - - private IAB iab = null; - - private static final int REQUEST_VPN = 1; - private static final int REQUEST_INVITE = 2; - private static final int REQUEST_LOGCAT = 3; - public static final int REQUEST_ROAMING = 4; - - private static final int MIN_SDK = Build.VERSION_CODES.LOLLIPOP_MR1; - - public static final String ACTION_RULES_CHANGED = "eu.faircode.netguard.ACTION_RULES_CHANGED"; - public static final String ACTION_QUEUE_CHANGED = "eu.faircode.netguard.ACTION_QUEUE_CHANGED"; - public static final String EXTRA_REFRESH = "Refresh"; - public static final String EXTRA_SEARCH = "Search"; - public static final String EXTRA_RELATED = "Related"; - public static final String EXTRA_APPROVE = "Approve"; - public static final String EXTRA_LOGCAT = "Logcat"; - public static final String EXTRA_CONNECTED = "Connected"; - public static final String EXTRA_METERED = "Metered"; - public static final String EXTRA_SIZE = "Size"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); - Util.logExtras(getIntent()); - - // Check minimum Android version - if (Build.VERSION.SDK_INT < MIN_SDK) { - Log.i(TAG, "SDK=" + Build.VERSION.SDK_INT); - super.onCreate(savedInstanceState); - setContentView(R.layout.android); - return; - } - - // Check for Xposed - if (Util.hasXposed(this)) { - Log.i(TAG, "Xposed running"); - super.onCreate(savedInstanceState); - setContentView(R.layout.xposed); - return; - } - - Util.setTheme(this); - super.onCreate(savedInstanceState); - setContentView(R.layout.main); - - running = true; - - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean enabled = prefs.getBoolean("enabled", false); - boolean initialized = prefs.getBoolean("initialized", false); - - // Upgrade - ReceiverAutostart.upgrade(initialized, this); - - if (!getIntent().hasExtra(EXTRA_APPROVE)) { - if (enabled) - ServiceSinkhole.start("UI", this); - else - ServiceSinkhole.stop("UI", this, false); - } - - // Action bar - final View actionView = getLayoutInflater().inflate(R.layout.actionmain, null, false); - ivIcon = actionView.findViewById(R.id.ivIcon); - ivQueue = actionView.findViewById(R.id.ivQueue); - swEnabled = actionView.findViewById(R.id.swEnabled); - ivMetered = actionView.findViewById(R.id.ivMetered); - - // Icon - ivIcon.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - menu_about(); - return true; - } - }); - - // Title - getSupportActionBar().setTitle(null); - - // Netguard is busy - ivQueue.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - int location[] = new int[2]; - actionView.getLocationOnScreen(location); - Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_queue, Toast.LENGTH_LONG); - toast.setGravity( - Gravity.TOP | Gravity.LEFT, - location[0] + ivQueue.getLeft(), - Math.round(location[1] + ivQueue.getBottom() - toast.getView().getPaddingTop())); - toast.show(); - return true; - } - }); - - // On/off switch - swEnabled.setChecked(enabled); - swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - Log.i(TAG, "Switch=" + isChecked); - prefs.edit().putBoolean("enabled", isChecked).apply(); - - if (isChecked) { - try { - String alwaysOn = Settings.Secure.getString(getContentResolver(), "always_on_vpn_app"); - Log.i(TAG, "Always-on=" + alwaysOn); - if (!TextUtils.isEmpty(alwaysOn)) - if (getPackageName().equals(alwaysOn)) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q && - prefs.getBoolean("filter", false)) { - int lockdown = Settings.Secure.getInt(getContentResolver(), "always_on_vpn_lockdown", 0); - Log.i(TAG, "Lockdown=" + lockdown); - if (lockdown != 0) { - swEnabled.setChecked(false); - Toast.makeText(ActivityMain.this, R.string.msg_always_on_lockdown, Toast.LENGTH_LONG).show(); - return; - } - } - } else { - swEnabled.setChecked(false); - Toast.makeText(ActivityMain.this, R.string.msg_always_on, Toast.LENGTH_LONG).show(); - return; - } - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - boolean filter = prefs.getBoolean("filter", false); - if (filter && Util.isPrivateDns(ActivityMain.this)) - Toast.makeText(ActivityMain.this, R.string.msg_private_dns, Toast.LENGTH_LONG).show(); - - try { - final Intent prepare = VpnService.prepare(ActivityMain.this); - if (prepare == null) { - Log.i(TAG, "Prepare done"); - onActivityResult(REQUEST_VPN, RESULT_OK, null); - } else { - // Show dialog - LayoutInflater inflater = LayoutInflater.from(ActivityMain.this); - View view = inflater.inflate(R.layout.vpn, null, false); - dialogVpn = new AlertDialog.Builder(ActivityMain.this) - .setView(view) - .setCancelable(false) - .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (running) { - Log.i(TAG, "Start intent=" + prepare); - try { - // com.android.vpndialogs.ConfirmDialog required - startActivityForResult(prepare, REQUEST_VPN); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - onActivityResult(REQUEST_VPN, RESULT_CANCELED, null); - prefs.edit().putBoolean("enabled", false).apply(); - } - } - } - }) - .setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialogInterface) { - dialogVpn = null; - } - }) - .create(); - dialogVpn.show(); - } - } catch (Throwable ex) { - // Prepare failed - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - prefs.edit().putBoolean("enabled", false).apply(); - } - - } else - ServiceSinkhole.stop("switch off", ActivityMain.this, false); - } - }); - if (enabled) - checkDoze(); - - // Network is metered - ivMetered.setOnLongClickListener(new View.OnLongClickListener() { - @Override - public boolean onLongClick(View view) { - int location[] = new int[2]; - actionView.getLocationOnScreen(location); - Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG); - toast.setGravity( - Gravity.TOP | Gravity.LEFT, - location[0] + ivMetered.getLeft(), - Math.round(location[1] + ivMetered.getBottom() - toast.getView().getPaddingTop())); - toast.show(); - return true; - } - }); - - getSupportActionBar().setDisplayShowCustomEnabled(true); - getSupportActionBar().setCustomView(actionView); - - // Disabled warning - TextView tvDisabled = findViewById(R.id.tvDisabled); - tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE); - - // Application list - RecyclerView rvApplication = findViewById(R.id.rvApplication); - rvApplication.setHasFixedSize(false); - LinearLayoutManager llm = new LinearLayoutManager(this); - llm.setAutoMeasureEnabled(true); - rvApplication.setLayoutManager(llm); - adapter = new AdapterRule(this, findViewById(R.id.vwPopupAnchor)); - rvApplication.setAdapter(adapter); - - // Swipe to refresh - TypedValue tv = new TypedValue(); - getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); - swipeRefresh = findViewById(R.id.swipeRefresh); - swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE); - swipeRefresh.setProgressBackgroundColorSchemeColor(tv.data); - swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { - @Override - public void onRefresh() { - Rule.clearCache(ActivityMain.this); - ServiceSinkhole.reload("pull", ActivityMain.this, false); - updateApplicationList(null); - } - }); - - // Hint usage - final LinearLayout llUsage = findViewById(R.id.llUsage); - Button btnUsage = findViewById(R.id.btnUsage); - boolean hintUsage = prefs.getBoolean("hint_usage", true); - llUsage.setVisibility(hintUsage ? View.VISIBLE : View.GONE); - btnUsage.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - prefs.edit().putBoolean("hint_usage", false).apply(); - llUsage.setVisibility(View.GONE); - showHints(); - } - }); - - final LinearLayout llFairEmail = findViewById(R.id.llFairEmail); - TextView tvFairEmail = findViewById(R.id.tvFairEmail); - tvFairEmail.setMovementMethod(LinkMovementMethod.getInstance()); - Button btnFairEmail = findViewById(R.id.btnFairEmail); - boolean hintFairEmail = prefs.getBoolean("hint_fairemail", true); - llFairEmail.setVisibility(hintFairEmail ? View.VISIBLE : View.GONE); - btnFairEmail.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - prefs.edit().putBoolean("hint_fairemail", false).apply(); - llFairEmail.setVisibility(View.GONE); - } - }); - - showHints(); - - // Listen for preference changes - prefs.registerOnSharedPreferenceChangeListener(this); - - // Listen for rule set changes - IntentFilter ifr = new IntentFilter(ACTION_RULES_CHANGED); - LocalBroadcastManager.getInstance(this).registerReceiver(onRulesChanged, ifr); - - // Listen for queue changes - IntentFilter ifq = new IntentFilter(ACTION_QUEUE_CHANGED); - LocalBroadcastManager.getInstance(this).registerReceiver(onQueueChanged, ifq); - - // Listen for added/removed applications - IntentFilter intentFilter = new IntentFilter(); - intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED); - intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED); - intentFilter.addDataScheme("package"); - registerReceiver(packageChangedReceiver, intentFilter); - - // First use - if (!initialized) { - // Create view - LayoutInflater inflater = LayoutInflater.from(this); - View view = inflater.inflate(R.layout.first, null, false); - - TextView tvFirst = view.findViewById(R.id.tvFirst); - TextView tvEula = view.findViewById(R.id.tvEula); - TextView tvPrivacy = view.findViewById(R.id.tvPrivacy); - tvFirst.setMovementMethod(LinkMovementMethod.getInstance()); - tvEula.setMovementMethod(LinkMovementMethod.getInstance()); - tvPrivacy.setMovementMethod(LinkMovementMethod.getInstance()); - - // Show dialog - dialogFirst = new AlertDialog.Builder(this) - .setView(view) - .setCancelable(false) - .setPositiveButton(R.string.app_agree, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (running) { - prefs.edit().putBoolean("initialized", true).apply(); - } - } - }) - .setNegativeButton(R.string.app_disagree, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (running) - finish(); - } - }) - .setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialogInterface) { - dialogFirst = null; - } - }) - .create(); - dialogFirst.show(); - } - - // Fill application list - updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH)); - - // Update IAB SKUs - try { - iab = new IAB(new IAB.Delegate() { - @Override - public void onReady(IAB iab) { - try { - iab.updatePurchases(); - - if (!IAB.isPurchased(ActivityPro.SKU_LOG, ActivityMain.this)) - prefs.edit().putBoolean("log", false).apply(); - if (!IAB.isPurchased(ActivityPro.SKU_THEME, ActivityMain.this)) { - if (!"teal".equals(prefs.getString("theme", "teal"))) - prefs.edit().putString("theme", "teal").apply(); - } - if (!IAB.isPurchased(ActivityPro.SKU_NOTIFY, ActivityMain.this)) - prefs.edit().putBoolean("install", false).apply(); - if (!IAB.isPurchased(ActivityPro.SKU_SPEED, ActivityMain.this)) - prefs.edit().putBoolean("show_stats", false).apply(); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } finally { - iab.unbind(); - } - } - }, this); - iab.bind(); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - // Support - LinearLayout llSupport = findViewById(R.id.llSupport); - TextView tvSupport = findViewById(R.id.tvSupport); - - SpannableString content = new SpannableString(getString(R.string.app_support)); - content.setSpan(new UnderlineSpan(), 0, content.length(), 0); - tvSupport.setText(content); - - llSupport.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(getIntentPro(ActivityMain.this)); - } - }); - - // Handle intent - checkExtras(getIntent()); - } - - @Override - protected void onNewIntent(Intent intent) { - Log.i(TAG, "New intent"); - Util.logExtras(intent); - super.onNewIntent(intent); - - if (Build.VERSION.SDK_INT < MIN_SDK || Util.hasXposed(this)) - return; - - setIntent(intent); - - if (Build.VERSION.SDK_INT >= MIN_SDK) { - if (intent.hasExtra(EXTRA_REFRESH)) - updateApplicationList(intent.getStringExtra(EXTRA_SEARCH)); - else - updateSearch(intent.getStringExtra(EXTRA_SEARCH)); - checkExtras(intent); - } - } - - @Override - protected void onResume() { - Log.i(TAG, "Resume"); - - if (Build.VERSION.SDK_INT < MIN_SDK || Util.hasXposed(this)) { - super.onResume(); - return; - } - - DatabaseHelper.getInstance(this).addAccessChangedListener(accessChangedListener); - if (adapter != null) - adapter.notifyDataSetChanged(); - - PackageManager pm = getPackageManager(); - LinearLayout llSupport = findViewById(R.id.llSupport); - llSupport.setVisibility( - IAB.isPurchasedAny(this) || getIntentPro(this).resolveActivity(pm) == null - ? View.GONE : View.VISIBLE); - - super.onResume(); - } - - @Override - protected void onPause() { - Log.i(TAG, "Pause"); - super.onPause(); - - if (Build.VERSION.SDK_INT < MIN_SDK || Util.hasXposed(this)) - return; - - DatabaseHelper.getInstance(this).removeAccessChangedListener(accessChangedListener); - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - Log.i(TAG, "Config"); - super.onConfigurationChanged(newConfig); - - if (Build.VERSION.SDK_INT < MIN_SDK || Util.hasXposed(this)) - return; - } - - @Override - public void onDestroy() { - Log.i(TAG, "Destroy"); - - if (Build.VERSION.SDK_INT < MIN_SDK || Util.hasXposed(this)) { - super.onDestroy(); - return; - } - - running = false; - adapter = null; - - PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this); - - LocalBroadcastManager.getInstance(this).unregisterReceiver(onRulesChanged); - LocalBroadcastManager.getInstance(this).unregisterReceiver(onQueueChanged); - unregisterReceiver(packageChangedReceiver); - - if (dialogFirst != null) { - dialogFirst.dismiss(); - dialogFirst = null; - } - if (dialogVpn != null) { - dialogVpn.dismiss(); - dialogVpn = null; - } - if (dialogDoze != null) { - dialogDoze.dismiss(); - dialogDoze = null; - } - if (dialogLegend != null) { - dialogLegend.dismiss(); - dialogLegend = null; - } - if (dialogAbout != null) { - dialogAbout.dismiss(); - dialogAbout = null; - } - - if (iab != null) { - iab.unbind(); - iab = null; - } - - super.onDestroy(); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, final Intent data) { - Log.i(TAG, "onActivityResult request=" + requestCode + " result=" + requestCode + " ok=" + (resultCode == RESULT_OK)); - Util.logExtras(data); - - if (requestCode == REQUEST_VPN) { - // Handle VPN approval - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.edit().putBoolean("enabled", resultCode == RESULT_OK).apply(); - if (resultCode == RESULT_OK) { - ServiceSinkhole.start("prepared", this); - - Toast on = Toast.makeText(ActivityMain.this, R.string.msg_on, Toast.LENGTH_LONG); - on.setGravity(Gravity.CENTER, 0, 0); - on.show(); - - checkDoze(); - } else if (resultCode == RESULT_CANCELED) - Toast.makeText(this, R.string.msg_vpn_cancelled, Toast.LENGTH_LONG).show(); - - } else if (requestCode == REQUEST_INVITE) { - // Do nothing - - } else if (requestCode == REQUEST_LOGCAT) { - // Send logcat by e-mail - if (resultCode == RESULT_OK) { - Uri target = data.getData(); - if (data.hasExtra("org.openintents.extra.DIR_PATH")) - target = Uri.parse(target + "/logcat.txt"); - Log.i(TAG, "Export URI=" + target); - Util.sendLogcat(target, this); - } - - } else { - Log.w(TAG, "Unknown activity result request=" + requestCode); - super.onActivityResult(requestCode, resultCode, data); - } - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - if (requestCode == REQUEST_ROAMING) - if (grantResults[0] == PackageManager.PERMISSION_GRANTED) - ServiceSinkhole.reload("permission granted", this, false); - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences prefs, String name) { - Log.i(TAG, "Preference " + name + "=" + prefs.getAll().get(name)); - if ("enabled".equals(name)) { - // Get enabled - boolean enabled = prefs.getBoolean(name, false); - - // Display disabled warning - TextView tvDisabled = findViewById(R.id.tvDisabled); - tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE); - - // Check switch state - SwitchCompat swEnabled = getSupportActionBar().getCustomView().findViewById(R.id.swEnabled); - if (swEnabled.isChecked() != enabled) - swEnabled.setChecked(enabled); - - } else if ("whitelist_wifi".equals(name) || - "screen_on".equals(name) || - "screen_wifi".equals(name) || - "whitelist_other".equals(name) || - "screen_other".equals(name) || - "whitelist_roaming".equals(name) || - "show_user".equals(name) || - "show_system".equals(name) || - "show_nointernet".equals(name) || - "show_disabled".equals(name) || - "sort".equals(name) || - "imported".equals(name)) { - updateApplicationList(null); - - final LinearLayout llWhitelist = findViewById(R.id.llWhitelist); - boolean screen_on = prefs.getBoolean("screen_on", true); - boolean whitelist_wifi = prefs.getBoolean("whitelist_wifi", false); - boolean whitelist_other = prefs.getBoolean("whitelist_other", false); - boolean hintWhitelist = prefs.getBoolean("hint_whitelist", true); - llWhitelist.setVisibility(!(whitelist_wifi || whitelist_other) && screen_on && hintWhitelist ? View.VISIBLE : View.GONE); - - } else if ("manage_system".equals(name)) { - invalidateOptionsMenu(); - updateApplicationList(null); - - LinearLayout llSystem = findViewById(R.id.llSystem); - boolean system = prefs.getBoolean("manage_system", false); - boolean hint = prefs.getBoolean("hint_system", true); - llSystem.setVisibility(!system && hint ? View.VISIBLE : View.GONE); - - } else if ("theme".equals(name) || "dark_theme".equals(name)) - recreate(); - } - - private DatabaseHelper.AccessChangedListener accessChangedListener = new DatabaseHelper.AccessChangedListener() { - @Override - public void onChanged() { - runOnUiThread(new Runnable() { - @Override - public void run() { - if (adapter != null && adapter.isLive()) - adapter.notifyDataSetChanged(); - } - }); - } - }; - - private BroadcastReceiver onRulesChanged = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - Log.i(TAG, "Received " + intent); - Util.logExtras(intent); - - if (adapter != null) - if (intent.hasExtra(EXTRA_CONNECTED) && intent.hasExtra(EXTRA_METERED)) { - ivIcon.setImageResource(Util.isNetworkActive(ActivityMain.this) - ? R.drawable.ic_security_white_24dp - : R.drawable.ic_security_white_24dp_60); - if (intent.getBooleanExtra(EXTRA_CONNECTED, false)) { - if (intent.getBooleanExtra(EXTRA_METERED, false)) - adapter.setMobileActive(); - else - adapter.setWifiActive(); - ivMetered.setVisibility(Util.isMeteredNetwork(ActivityMain.this) ? View.VISIBLE : View.INVISIBLE); - } else { - adapter.setDisconnected(); - ivMetered.setVisibility(View.INVISIBLE); - } - } else - updateApplicationList(null); - } - }; - - private BroadcastReceiver onQueueChanged = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - Log.i(TAG, "Received " + intent); - Util.logExtras(intent); - int size = intent.getIntExtra(EXTRA_SIZE, -1); - ivIcon.setVisibility(size == 0 ? View.VISIBLE : View.GONE); - ivQueue.setVisibility(size == 0 ? View.GONE : View.VISIBLE); - } - }; - - private BroadcastReceiver packageChangedReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - Log.i(TAG, "Received " + intent); - Util.logExtras(intent); - updateApplicationList(null); - } - }; - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - if (Build.VERSION.SDK_INT < MIN_SDK) - return false; - - PackageManager pm = getPackageManager(); - - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.main, menu); - - // Search - menuSearch = menu.findItem(R.id.menu_search); - menuSearch.setOnActionExpandListener(new MenuItem.OnActionExpandListener() { - @Override - public boolean onMenuItemActionExpand(MenuItem item) { - return true; - } - - @Override - public boolean onMenuItemActionCollapse(MenuItem item) { - if (getIntent().hasExtra(EXTRA_SEARCH) && !getIntent().getBooleanExtra(EXTRA_RELATED, false)) - finish(); - return true; - } - }); - - final SearchView searchView = (SearchView) menuSearch.getActionView(); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { - @Override - public boolean onQueryTextSubmit(String query) { - if (adapter != null) - adapter.getFilter().filter(query); - searchView.clearFocus(); - return true; - } - - @Override - public boolean onQueryTextChange(String newText) { - if (adapter != null) - adapter.getFilter().filter(newText); - return true; - } - }); - searchView.setOnCloseListener(new SearchView.OnCloseListener() { - @Override - public boolean onClose() { - Intent intent = getIntent(); - intent.removeExtra(EXTRA_SEARCH); - - if (adapter != null) - adapter.getFilter().filter(null); - return true; - } - }); - String search = getIntent().getStringExtra(EXTRA_SEARCH); - if (search != null) { - menuSearch.expandActionView(); - searchView.setQuery(search, true); - } - - markPro(menu.findItem(R.id.menu_log), ActivityPro.SKU_LOG); - if (!IAB.isPurchasedAny(this)) - markPro(menu.findItem(R.id.menu_pro), null); - - if (!Util.hasValidFingerprint(this) || getIntentInvite(this).resolveActivity(pm) == null) - menu.removeItem(R.id.menu_invite); - - if (getIntentSupport().resolveActivity(getPackageManager()) == null) - menu.removeItem(R.id.menu_support); - - menu.findItem(R.id.menu_apps).setEnabled(getIntentApps(this).resolveActivity(pm) != null); - - return true; - } - - private void markPro(MenuItem menu, String sku) { - if (sku == null || !IAB.isPurchased(sku, this)) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean dark = prefs.getBoolean("dark_theme", false); - SpannableStringBuilder ssb = new SpannableStringBuilder(" " + menu.getTitle()); - ssb.setSpan(new ImageSpan(this, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - menu.setTitle(ssb); - } - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - - if (prefs.getBoolean("manage_system", false)) { - menu.findItem(R.id.menu_app_user).setChecked(prefs.getBoolean("show_user", true)); - menu.findItem(R.id.menu_app_system).setChecked(prefs.getBoolean("show_system", false)); - } else { - Menu submenu = menu.findItem(R.id.menu_filter).getSubMenu(); - submenu.removeItem(R.id.menu_app_user); - submenu.removeItem(R.id.menu_app_system); - } - - menu.findItem(R.id.menu_app_nointernet).setChecked(prefs.getBoolean("show_nointernet", true)); - menu.findItem(R.id.menu_app_disabled).setChecked(prefs.getBoolean("show_disabled", true)); - - String sort = prefs.getString("sort", "name"); - if ("uid".equals(sort)) - menu.findItem(R.id.menu_sort_uid).setChecked(true); - else - menu.findItem(R.id.menu_sort_name).setChecked(true); - - menu.findItem(R.id.menu_lockdown).setChecked(prefs.getBoolean("lockdown", false)); - - return super.onPrepareOptionsMenu(menu); - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - Log.i(TAG, "Menu=" + item.getTitle()); - - // Handle item selection - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - switch (item.getItemId()) { - case R.id.menu_app_user: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("show_user", item.isChecked()).apply(); - return true; - - case R.id.menu_app_system: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("show_system", item.isChecked()).apply(); - return true; - - case R.id.menu_app_nointernet: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("show_nointernet", item.isChecked()).apply(); - return true; - - case R.id.menu_app_disabled: - item.setChecked(!item.isChecked()); - prefs.edit().putBoolean("show_disabled", item.isChecked()).apply(); - return true; - - case R.id.menu_sort_name: - item.setChecked(true); - prefs.edit().putString("sort", "name").apply(); - return true; - - case R.id.menu_sort_uid: - item.setChecked(true); - prefs.edit().putString("sort", "uid").apply(); - return true; - - case R.id.menu_lockdown: - menu_lockdown(item); - return true; - - case R.id.menu_log: - if (Util.canFilter(this)) - if (IAB.isPurchased(ActivityPro.SKU_LOG, this)) - startActivity(new Intent(this, ActivityLog.class)); - else - startActivity(new Intent(this, ActivityPro.class)); - else - Toast.makeText(this, R.string.msg_unavailable, Toast.LENGTH_SHORT).show(); - return true; - - case R.id.menu_settings: - startActivity(new Intent(this, ActivitySettings.class)); - return true; - - case R.id.menu_pro: - startActivity(new Intent(ActivityMain.this, ActivityPro.class)); - return true; - - case R.id.menu_invite: - startActivityForResult(getIntentInvite(this), REQUEST_INVITE); - return true; - - case R.id.menu_legend: - menu_legend(); - return true; - - case R.id.menu_support: - startActivity(getIntentSupport()); - return true; - - case R.id.menu_about: - menu_about(); - return true; - - case R.id.menu_apps: - menu_apps(); - return true; - - default: - return super.onOptionsItemSelected(item); - } - } - - private void showHints() { - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean hintUsage = prefs.getBoolean("hint_usage", true); - - // Hint white listing - final LinearLayout llWhitelist = findViewById(R.id.llWhitelist); - Button btnWhitelist = findViewById(R.id.btnWhitelist); - boolean whitelist_wifi = prefs.getBoolean("whitelist_wifi", false); - boolean whitelist_other = prefs.getBoolean("whitelist_other", false); - boolean hintWhitelist = prefs.getBoolean("hint_whitelist", true); - llWhitelist.setVisibility(!(whitelist_wifi || whitelist_other) && hintWhitelist && !hintUsage ? View.VISIBLE : View.GONE); - btnWhitelist.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - prefs.edit().putBoolean("hint_whitelist", false).apply(); - llWhitelist.setVisibility(View.GONE); - } - }); - - // Hint push messages - final LinearLayout llPush = findViewById(R.id.llPush); - Button btnPush = findViewById(R.id.btnPush); - boolean hintPush = prefs.getBoolean("hint_push", true); - llPush.setVisibility(hintPush && !hintUsage ? View.VISIBLE : View.GONE); - btnPush.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - prefs.edit().putBoolean("hint_push", false).apply(); - llPush.setVisibility(View.GONE); - } - }); - - // Hint system applications - final LinearLayout llSystem = findViewById(R.id.llSystem); - Button btnSystem = findViewById(R.id.btnSystem); - boolean system = prefs.getBoolean("manage_system", false); - boolean hintSystem = prefs.getBoolean("hint_system", true); - llSystem.setVisibility(!system && hintSystem ? View.VISIBLE : View.GONE); - btnSystem.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - prefs.edit().putBoolean("hint_system", false).apply(); - llSystem.setVisibility(View.GONE); - } - }); - } - - private void checkExtras(Intent intent) { - // Approve request - if (intent.hasExtra(EXTRA_APPROVE)) { - Log.i(TAG, "Requesting VPN approval"); - swEnabled.toggle(); - } - - if (intent.hasExtra(EXTRA_LOGCAT)) { - Log.i(TAG, "Requesting logcat"); - Intent logcat = getIntentLogcat(); - if (logcat.resolveActivity(getPackageManager()) != null) - startActivityForResult(logcat, REQUEST_LOGCAT); - } - } - - private void updateApplicationList(final String search) { - Log.i(TAG, "Update search=" + search); - - new AsyncTask>() { - private boolean refreshing = true; - - @Override - protected void onPreExecute() { - swipeRefresh.post(new Runnable() { - @Override - public void run() { - if (refreshing) - swipeRefresh.setRefreshing(true); - } - }); - } - - @Override - protected List doInBackground(Object... arg) { - return Rule.getRules(false, ActivityMain.this); - } - - @Override - protected void onPostExecute(List result) { - if (running) { - if (adapter != null) { - adapter.set(result); - updateSearch(search); - } - - if (swipeRefresh != null) { - refreshing = false; - swipeRefresh.setRefreshing(false); - } - } - } - }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private void updateSearch(String search) { - if (menuSearch != null) { - SearchView searchView = (SearchView) menuSearch.getActionView(); - if (search == null) { - if (menuSearch.isActionViewExpanded()) - adapter.getFilter().filter(searchView.getQuery().toString()); - } else { - menuSearch.expandActionView(); - searchView.setQuery(search, true); - } - } - } - - private void checkDoze() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - final Intent doze = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS); - if (Util.batteryOptimizing(this) && getPackageManager().resolveActivity(doze, 0) != null) { - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - if (!prefs.getBoolean("nodoze", false)) { - LayoutInflater inflater = LayoutInflater.from(this); - View view = inflater.inflate(R.layout.doze, null, false); - final CheckBox cbDontAsk = view.findViewById(R.id.cbDontAsk); - dialogDoze = new AlertDialog.Builder(this) - .setView(view) - .setCancelable(true) - .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - prefs.edit().putBoolean("nodoze", cbDontAsk.isChecked()).apply(); - startActivity(doze); - } - }) - .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - prefs.edit().putBoolean("nodoze", cbDontAsk.isChecked()).apply(); - } - }) - .setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialogInterface) { - dialogDoze = null; - checkDataSaving(); - } - }) - .create(); - dialogDoze.show(); - } else - checkDataSaving(); - } else - checkDataSaving(); - } - } - - private void checkDataSaving() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - final Intent settings = new Intent( - Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS, - Uri.parse("package:" + getPackageName())); - if (Util.dataSaving(this) && getPackageManager().resolveActivity(settings, 0) != null) - try { - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - if (!prefs.getBoolean("nodata", false)) { - LayoutInflater inflater = LayoutInflater.from(this); - View view = inflater.inflate(R.layout.datasaving, null, false); - final CheckBox cbDontAsk = view.findViewById(R.id.cbDontAsk); - dialogDoze = new AlertDialog.Builder(this) - .setView(view) - .setCancelable(true) - .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - prefs.edit().putBoolean("nodata", cbDontAsk.isChecked()).apply(); - startActivity(settings); - } - }) - .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - prefs.edit().putBoolean("nodata", cbDontAsk.isChecked()).apply(); - } - }) - .setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialogInterface) { - dialogDoze = null; - } - }) - .create(); - dialogDoze.show(); - } - } catch (Throwable ex) { - Log.e(TAG, ex + "\n" + ex.getStackTrace()); - } - } - } - - private void menu_legend() { - TypedValue tv = new TypedValue(); - getTheme().resolveAttribute(R.attr.colorOn, tv, true); - int colorOn = tv.data; - getTheme().resolveAttribute(R.attr.colorOff, tv, true); - int colorOff = tv.data; - - // Create view - LayoutInflater inflater = LayoutInflater.from(this); - View view = inflater.inflate(R.layout.legend, null, false); - ImageView ivLockdownOn = view.findViewById(R.id.ivLockdownOn); - ImageView ivWifiOn = view.findViewById(R.id.ivWifiOn); - ImageView ivWifiOff = view.findViewById(R.id.ivWifiOff); - ImageView ivOtherOn = view.findViewById(R.id.ivOtherOn); - ImageView ivOtherOff = view.findViewById(R.id.ivOtherOff); - ImageView ivScreenOn = view.findViewById(R.id.ivScreenOn); - ImageView ivHostAllowed = view.findViewById(R.id.ivHostAllowed); - ImageView ivHostBlocked = view.findViewById(R.id.ivHostBlocked); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrapLockdownOn = DrawableCompat.wrap(ivLockdownOn.getDrawable()); - Drawable wrapWifiOn = DrawableCompat.wrap(ivWifiOn.getDrawable()); - Drawable wrapWifiOff = DrawableCompat.wrap(ivWifiOff.getDrawable()); - Drawable wrapOtherOn = DrawableCompat.wrap(ivOtherOn.getDrawable()); - Drawable wrapOtherOff = DrawableCompat.wrap(ivOtherOff.getDrawable()); - Drawable wrapScreenOn = DrawableCompat.wrap(ivScreenOn.getDrawable()); - Drawable wrapHostAllowed = DrawableCompat.wrap(ivHostAllowed.getDrawable()); - Drawable wrapHostBlocked = DrawableCompat.wrap(ivHostBlocked.getDrawable()); - - DrawableCompat.setTint(wrapLockdownOn, colorOff); - DrawableCompat.setTint(wrapWifiOn, colorOn); - DrawableCompat.setTint(wrapWifiOff, colorOff); - DrawableCompat.setTint(wrapOtherOn, colorOn); - DrawableCompat.setTint(wrapOtherOff, colorOff); - DrawableCompat.setTint(wrapScreenOn, colorOn); - DrawableCompat.setTint(wrapHostAllowed, colorOn); - DrawableCompat.setTint(wrapHostBlocked, colorOff); - } - - - // Show dialog - dialogLegend = new AlertDialog.Builder(this) - .setView(view) - .setCancelable(true) - .setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialogInterface) { - dialogLegend = null; - } - }) - .create(); - dialogLegend.show(); - } - - private void menu_lockdown(MenuItem item) { - item.setChecked(!item.isChecked()); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.edit().putBoolean("lockdown", item.isChecked()).apply(); - ServiceSinkhole.reload("lockdown", this, false); - WidgetLockdown.updateWidgets(this); - } - - private void menu_about() { - // Create view - LayoutInflater inflater = LayoutInflater.from(this); - View view = inflater.inflate(R.layout.about, null, false); - TextView tvVersionName = view.findViewById(R.id.tvVersionName); - TextView tvVersionCode = view.findViewById(R.id.tvVersionCode); - Button btnRate = view.findViewById(R.id.btnRate); - TextView tvEula = view.findViewById(R.id.tvEula); - TextView tvPrivacy = view.findViewById(R.id.tvPrivacy); - - // Show version - tvVersionName.setText(Util.getSelfVersionName(this)); - if (!Util.hasValidFingerprint(this)) - tvVersionName.setTextColor(Color.GRAY); - tvVersionCode.setText(Integer.toString(Util.getSelfVersionCode(this))); - - // Handle license - tvEula.setMovementMethod(LinkMovementMethod.getInstance()); - tvPrivacy.setMovementMethod(LinkMovementMethod.getInstance()); - - // Handle logcat - view.setOnClickListener(new View.OnClickListener() { - private short tap = 0; - private Toast toast = Toast.makeText(ActivityMain.this, "", Toast.LENGTH_SHORT); - - @Override - public void onClick(View view) { - tap++; - if (tap == 7) { - tap = 0; - toast.cancel(); - - Intent intent = getIntentLogcat(); - if (intent.resolveActivity(getPackageManager()) != null) - startActivityForResult(intent, REQUEST_LOGCAT); - - } else if (tap > 3) { - toast.setText(Integer.toString(7 - tap)); - toast.show(); - } - } - }); - - // Handle rate - btnRate.setVisibility(getIntentRate(this).resolveActivity(getPackageManager()) == null ? View.GONE : View.VISIBLE); - btnRate.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - startActivity(getIntentRate(ActivityMain.this)); - } - }); - - // Show dialog - dialogAbout = new AlertDialog.Builder(this) - .setView(view) - .setCancelable(true) - .setOnDismissListener(new DialogInterface.OnDismissListener() { - @Override - public void onDismiss(DialogInterface dialogInterface) { - dialogAbout = null; - } - }) - .create(); - dialogAbout.show(); - } - - private void menu_apps() { - startActivity(getIntentApps(this)); - } - - private static Intent getIntentPro(Context context) { - if (Util.isPlayStoreInstall(context)) - return new Intent(context, ActivityPro.class); - else { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("https://contact.faircode.eu/?product=netguardstandalone")); - return intent; - } - } - - private static Intent getIntentInvite(Context context) { - Intent intent = new Intent(Intent.ACTION_SEND); - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.app_name)); - intent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.msg_try) + "\n\nhttps://www.netguard.me/\n\n"); - return intent; - } - - private static Intent getIntentApps(Context context) { - return new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/dev?id=8420080860664580239")); - } - - private static Intent getIntentRate(Context context) { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + context.getPackageName())); - if (intent.resolveActivity(context.getPackageManager()) == null) - intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + context.getPackageName())); - return intent; - } - - private static Intent getIntentSupport() { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md")); - return intent; - } - - private Intent getIntentLogcat() { - Intent intent; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { - if (Util.isPackageInstalled("org.openintents.filemanager", this)) { - intent = new Intent("org.openintents.action.PICK_DIRECTORY"); - } else { - intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("https://play.google.com/store/apps/details?id=org.openintents.filemanager")); - } - } else { - intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); - intent.addCategory(Intent.CATEGORY_OPENABLE); - intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_TITLE, "logcat.txt"); - } - return intent; - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityPro.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityPro.java deleted file mode 100644 index 063d360..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ActivityPro.java +++ /dev/null @@ -1,447 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.app.PendingIntent; -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.content.Intent; -import android.graphics.Paint; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.provider.Settings; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.WindowManager; -import android.widget.Button; -import android.widget.EditText; -import android.widget.ImageButton; -import android.widget.TextView; -import android.widget.Toast; - -import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.app.NavUtils; - -import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN; - -public class ActivityPro extends AppCompatActivity { - private static final String TAG = "NetGuard.Pro"; - - private IAB iab; - - // adb shell pm clear com.android.vending - // android.test.purchased - - private static final int SKU_LOG_ID = 1; - private static final int SKU_FILTER_ID = 2; - private static final int SKU_NOTIFY_ID = 3; - private static final int SKU_SPEED_ID = 4; - private static final int SKU_THEME_ID = 5; - private static final int SKU_PRO1_ID = 6; - private static final int SKU_SUPPORT1_ID = 7; - private static final int SKU_SUPPORT2_ID = 8; - - public static final String SKU_LOG = "log"; - public static final String SKU_FILTER = "filter"; - public static final String SKU_NOTIFY = "notify"; - public static final String SKU_SPEED = "speed"; - public static final String SKU_THEME = "theme"; - public static final String SKU_PRO1 = "pro1"; - public static final String SKU_SUPPORT1 = "support1"; - public static final String SKU_SUPPORT2 = "support2"; - public static final String SKU_DONATION = "donation"; - - @Override - protected void onCreate(Bundle savedInstanceState) { - Log.i(TAG, "Create"); - Util.setTheme(this); - super.onCreate(savedInstanceState); - setContentView(R.layout.pro); - - getSupportActionBar().setTitle(R.string.title_pro); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); - - // Initial state - updateState(); - - TextView tvLogTitle = findViewById(R.id.tvLogTitle); - TextView tvFilterTitle = findViewById(R.id.tvFilterTitle); - TextView tvNotifyTitle = findViewById(R.id.tvNotifyTitle); - TextView tvSpeedTitle = findViewById(R.id.tvSpeedTitle); - TextView tvThemeTitle = findViewById(R.id.tvThemeTitle); - TextView tvAllTitle = findViewById(R.id.tvAllTitle); - TextView tvDev1Title = findViewById(R.id.tvDev1Title); - TextView tvDev2Title = findViewById(R.id.tvDev2Title); - - tvLogTitle.setPaintFlags(tvLogTitle.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - tvFilterTitle.setPaintFlags(tvLogTitle.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - tvNotifyTitle.setPaintFlags(tvLogTitle.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - tvSpeedTitle.setPaintFlags(tvLogTitle.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - tvThemeTitle.setPaintFlags(tvLogTitle.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - tvAllTitle.setPaintFlags(tvLogTitle.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - tvDev1Title.setPaintFlags(tvLogTitle.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - tvDev2Title.setPaintFlags(tvLogTitle.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); - - View.OnClickListener listener = new View.OnClickListener() { - @Override - public void onClick(View view) { - String sku; - switch (view.getId()) { - case R.id.tvLogTitle: - sku = SKU_LOG; - break; - case R.id.tvFilterTitle: - sku = SKU_FILTER; - break; - case R.id.tvNotifyTitle: - sku = SKU_NOTIFY; - break; - case R.id.tvSpeedTitle: - sku = SKU_SPEED; - break; - case R.id.tvThemeTitle: - sku = SKU_THEME; - break; - case R.id.tvAllTitle: - sku = SKU_PRO1; - break; - case R.id.tvDev1Title: - sku = SKU_SUPPORT1; - break; - case R.id.tvDev2Title: - sku = SKU_SUPPORT2; - break; - default: - sku = SKU_PRO1; - break; - } - - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse("http://www.netguard.me/#" + sku)); - if (intent.resolveActivity(getPackageManager()) != null) - startActivity(intent); - } - }; - - tvLogTitle.setOnClickListener(listener); - tvFilterTitle.setOnClickListener(listener); - tvNotifyTitle.setOnClickListener(listener); - tvSpeedTitle.setOnClickListener(listener); - tvThemeTitle.setOnClickListener(listener); - tvAllTitle.setOnClickListener(listener); - tvDev1Title.setOnClickListener(listener); - tvDev2Title.setOnClickListener(listener); - - try { - iab = new IAB(new IAB.Delegate() { - @Override - public void onReady(final IAB iab) { - Log.i(TAG, "IAB ready"); - try { - iab.updatePurchases(); - updateState(); - - final Button btnLog = findViewById(R.id.btnLog); - final Button btnFilter = findViewById(R.id.btnFilter); - final Button btnNotify = findViewById(R.id.btnNotify); - final Button btnSpeed = findViewById(R.id.btnSpeed); - final Button btnTheme = findViewById(R.id.btnTheme); - final Button btnAll = findViewById(R.id.btnAll); - final Button btnDev1 = findViewById(R.id.btnDev1); - final Button btnDev2 = findViewById(R.id.btnDev2); - - View.OnClickListener listener = new View.OnClickListener() { - @Override - public void onClick(View view) { - try { - int id = 0; - PendingIntent pi = null; - if (view == btnLog) { - id = SKU_LOG_ID; - pi = iab.getBuyIntent(SKU_LOG, false); - } else if (view == btnFilter) { - id = SKU_FILTER_ID; - pi = iab.getBuyIntent(SKU_FILTER, false); - } else if (view == btnNotify) { - id = SKU_NOTIFY_ID; - pi = iab.getBuyIntent(SKU_NOTIFY, false); - } else if (view == btnSpeed) { - id = SKU_SPEED_ID; - pi = iab.getBuyIntent(SKU_SPEED, false); - } else if (view == btnTheme) { - id = SKU_THEME_ID; - pi = iab.getBuyIntent(SKU_THEME, false); - } else if (view == btnAll) { - id = SKU_PRO1_ID; - pi = iab.getBuyIntent(SKU_PRO1, false); - } else if (view == btnDev1) { - id = SKU_SUPPORT1_ID; - pi = iab.getBuyIntent(SKU_SUPPORT1, true); - } else if (view == btnDev2) { - id = SKU_SUPPORT2_ID; - pi = iab.getBuyIntent(SKU_SUPPORT2, true); - } - - if (id > 0 && pi != null) - startIntentSenderForResult(pi.getIntentSender(), id, new Intent(), 0, 0, 0); - } catch (Throwable ex) { - Log.i(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - }; - - btnLog.setOnClickListener(listener); - btnFilter.setOnClickListener(listener); - btnNotify.setOnClickListener(listener); - btnSpeed.setOnClickListener(listener); - btnTheme.setOnClickListener(listener); - btnAll.setOnClickListener(listener); - btnDev1.setOnClickListener(listener); - btnDev2.setOnClickListener(listener); - - btnLog.setEnabled(true); - btnFilter.setEnabled(true); - btnNotify.setEnabled(true); - btnSpeed.setEnabled(true); - btnTheme.setEnabled(true); - btnAll.setEnabled(true); - btnDev1.setEnabled(true); - btnDev2.setEnabled(true); - - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - }, this); - iab.bind(); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - - @Override - protected void onDestroy() { - Log.i(TAG, "Destroy"); - iab.unbind(); - iab = null; - super.onDestroy(); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.pro, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - Log.i(TAG, "Up"); - NavUtils.navigateUpFromSameTask(this); - return true; - case R.id.menu_challenge: - menu_challenge(); - return true; - default: - return super.onOptionsItemSelected(item); - } - } - - @Override - public boolean onPrepareOptionsMenu(Menu menu) { - if (IAB.isPurchased(SKU_DONATION, this) || Util.isPlayStoreInstall(this)) - menu.removeItem(R.id.menu_challenge); - - return super.onPrepareOptionsMenu(menu); - } - - private void menu_challenge() { - LayoutInflater inflater = LayoutInflater.from(this); - View view = inflater.inflate(R.layout.challenge, null, false); - - final AlertDialog dialog = new AlertDialog.Builder(this) - .setView(view) - .setCancelable(true) - .create(); - - String android_id = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID); - final String challenge = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? Build.SERIAL : "O3" + android_id); - String seed = (Build.VERSION.SDK_INT < Build.VERSION_CODES.O ? "NetGuard2" : "NetGuard3"); - - // Challenge - TextView tvChallenge = view.findViewById(R.id.tvChallenge); - tvChallenge.setText(challenge); - - ImageButton ibCopy = view.findViewById(R.id.ibCopy); - ibCopy.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText(getString(R.string.title_pro_challenge), challenge); - clipboard.setPrimaryClip(clip); - Toast.makeText(ActivityPro.this, android.R.string.copy, Toast.LENGTH_LONG).show(); - } - }); - - // Response - final EditText etResponse = view.findViewById(R.id.etResponse); - try { - final String response = Util.md5(challenge, seed); - etResponse.addTextChangedListener(new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - // Do nothing - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - // Do nothing - } - - @Override - public void afterTextChanged(Editable editable) { - if (response.equals(editable.toString().toUpperCase())) { - IAB.setBought(SKU_DONATION, ActivityPro.this); - dialog.dismiss(); - invalidateOptionsMenu(); - updateState(); - } - } - }); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - ImageButton ibPaste = view.findViewById(R.id.ibPaste); - ibPaste.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); - if (clipboard != null && - clipboard.hasPrimaryClip() && - clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN)) { - ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0); - etResponse.setText(item.getText().toString()); - } - } - }); - - dialog.show(); - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - if (resultCode == RESULT_OK) { - switch (requestCode) { - case SKU_LOG_ID: - IAB.setBought(SKU_LOG, this); - updateState(); - break; - case SKU_FILTER_ID: - IAB.setBought(SKU_FILTER, this); - updateState(); - break; - case SKU_NOTIFY_ID: - IAB.setBought(SKU_NOTIFY, this); - updateState(); - break; - case SKU_SPEED_ID: - IAB.setBought(SKU_SPEED, this); - updateState(); - break; - case SKU_THEME_ID: - IAB.setBought(SKU_THEME, this); - updateState(); - break; - case SKU_PRO1_ID: - IAB.setBought(SKU_PRO1, this); - updateState(); - break; - case SKU_SUPPORT1_ID: - IAB.setBought(SKU_SUPPORT1, this); - updateState(); - break; - case SKU_SUPPORT2_ID: - IAB.setBought(SKU_SUPPORT2, this); - updateState(); - break; - } - } - } - - private void updateState() { - Button btnLog = findViewById(R.id.btnLog); - Button btnFilter = findViewById(R.id.btnFilter); - Button btnNotify = findViewById(R.id.btnNotify); - Button btnSpeed = findViewById(R.id.btnSpeed); - Button btnTheme = findViewById(R.id.btnTheme); - Button btnAll = findViewById(R.id.btnAll); - Button btnDev1 = findViewById(R.id.btnDev1); - Button btnDev2 = findViewById(R.id.btnDev2); - TextView tvLog = findViewById(R.id.tvLog); - TextView tvFilter = findViewById(R.id.tvFilter); - TextView tvNotify = findViewById(R.id.tvNotify); - TextView tvSpeed = findViewById(R.id.tvSpeed); - TextView tvTheme = findViewById(R.id.tvTheme); - TextView tvAll = findViewById(R.id.tvAll); - TextView tvDev1 = findViewById(R.id.tvDev1); - TextView tvDev2 = findViewById(R.id.tvDev2); - - TextView tvLogUnavailable = findViewById(R.id.tvLogUnavailable); - TextView tvFilterUnavailable = findViewById(R.id.tvFilterUnavailable); - - boolean can = Util.canFilter(this); - - btnLog.setVisibility(IAB.isPurchased(SKU_LOG, this) || !can ? View.GONE : View.VISIBLE); - btnFilter.setVisibility(IAB.isPurchased(SKU_FILTER, this) || !can ? View.GONE : View.VISIBLE); - btnNotify.setVisibility(IAB.isPurchased(SKU_NOTIFY, this) ? View.GONE : View.VISIBLE); - btnSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, this) ? View.GONE : View.VISIBLE); - btnTheme.setVisibility(IAB.isPurchased(SKU_THEME, this) ? View.GONE : View.VISIBLE); - btnAll.setVisibility(IAB.isPurchased(SKU_PRO1, this) ? View.GONE : View.VISIBLE); - btnDev1.setVisibility(IAB.isPurchased(SKU_SUPPORT1, this) ? View.GONE : View.VISIBLE); - btnDev2.setVisibility(IAB.isPurchased(SKU_SUPPORT2, this) ? View.GONE : View.VISIBLE); - - tvLog.setVisibility(IAB.isPurchased(SKU_LOG, this) && can ? View.VISIBLE : View.GONE); - tvFilter.setVisibility(IAB.isPurchased(SKU_FILTER, this) && can ? View.VISIBLE : View.GONE); - tvNotify.setVisibility(IAB.isPurchased(SKU_NOTIFY, this) ? View.VISIBLE : View.GONE); - tvSpeed.setVisibility(IAB.isPurchased(SKU_SPEED, this) ? View.VISIBLE : View.GONE); - tvTheme.setVisibility(IAB.isPurchased(SKU_THEME, this) ? View.VISIBLE : View.GONE); - tvAll.setVisibility(IAB.isPurchased(SKU_PRO1, this) ? View.VISIBLE : View.GONE); - tvDev1.setVisibility(IAB.isPurchased(SKU_SUPPORT1, this) ? View.VISIBLE : View.GONE); - tvDev2.setVisibility(IAB.isPurchased(SKU_SUPPORT2, this) ? View.VISIBLE : View.GONE); - - tvLogUnavailable.setVisibility(can ? View.GONE : View.VISIBLE); - tvFilterUnavailable.setVisibility(can ? View.GONE : View.VISIBLE); - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterAccess.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterAccess.java deleted file mode 100644 index 1ddbc11..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterAccess.java +++ /dev/null @@ -1,186 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.Context; -import android.content.res.TypedArray; -import android.database.Cursor; -import android.graphics.drawable.Drawable; -import android.os.AsyncTask; -import android.os.Build; -import android.text.SpannableString; -import android.text.style.UnderlineSpan; -import android.util.TypedValue; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CursorAdapter; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.TextView; - -import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.view.ViewCompat; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.text.SimpleDateFormat; - -public class AdapterAccess extends CursorAdapter { - private int colVersion; - private int colProtocol; - private int colDaddr; - private int colDPort; - private int colTime; - private int colAllowed; - private int colBlock; - private int colCount; - private int colSent; - private int colReceived; - private int colConnections; - - private int colorText; - private int colorOn; - private int colorOff; - - public AdapterAccess(Context context, Cursor cursor) { - super(context, cursor, 0); - colVersion = cursor.getColumnIndex("version"); - colProtocol = cursor.getColumnIndex("protocol"); - colDaddr = cursor.getColumnIndex("daddr"); - colDPort = cursor.getColumnIndex("dport"); - colTime = cursor.getColumnIndex("time"); - colAllowed = cursor.getColumnIndex("allowed"); - colBlock = cursor.getColumnIndex("block"); - colCount = cursor.getColumnIndex("count"); - colSent = cursor.getColumnIndex("sent"); - colReceived = cursor.getColumnIndex("received"); - colConnections = cursor.getColumnIndex("connections"); - - TypedArray ta = context.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorSecondary}); - try { - colorText = ta.getColor(0, 0); - } finally { - ta.recycle(); - } - - TypedValue tv = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.colorOn, tv, true); - colorOn = tv.data; - context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); - colorOff = tv.data; - } - - @Override - public View newView(Context context, Cursor cursor, ViewGroup parent) { - return LayoutInflater.from(context).inflate(R.layout.access, parent, false); - } - - @Override - public void bindView(final View view, final Context context, final Cursor cursor) { - // Get values - final int version = cursor.getInt(colVersion); - final int protocol = cursor.getInt(colProtocol); - final String daddr = cursor.getString(colDaddr); - final int dport = cursor.getInt(colDPort); - long time = cursor.getLong(colTime); - int allowed = cursor.getInt(colAllowed); - int block = cursor.getInt(colBlock); - int count = cursor.getInt(colCount); - long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent); - long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived); - int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections); - - // Get views - TextView tvTime = view.findViewById(R.id.tvTime); - ImageView ivBlock = view.findViewById(R.id.ivBlock); - final TextView tvDest = view.findViewById(R.id.tvDest); - LinearLayout llTraffic = view.findViewById(R.id.llTraffic); - TextView tvConnections = view.findViewById(R.id.tvConnections); - TextView tvTraffic = view.findViewById(R.id.tvTraffic); - - // Set values - tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time)); - if (block < 0) - ivBlock.setImageDrawable(null); - else { - ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable()); - DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn); - } - } - - String dest = Util.getProtocolName(protocol, version, true) + - " " + daddr + (dport > 0 ? "/" + dport : "") + (count > 1 ? " ?" + count : ""); - SpannableString span = new SpannableString(dest); - span.setSpan(new UnderlineSpan(), 0, dest.length(), 0); - tvDest.setText(span); - - if (Util.isNumericAddress(daddr)) - new AsyncTask() { - @Override - protected void onPreExecute() { - ViewCompat.setHasTransientState(tvDest, true); - } - - @Override - protected String doInBackground(String... args) { - try { - return InetAddress.getByName(args[0]).getHostName(); - } catch (UnknownHostException ignored) { - return args[0]; - } - } - - @Override - protected void onPostExecute(String addr) { - tvDest.setText( - Util.getProtocolName(protocol, version, true) + - " >" + addr + (dport > 0 ? "/" + dport : "")); - ViewCompat.setHasTransientState(tvDest, false); - } - }.execute(daddr); - - if (allowed < 0) - tvDest.setTextColor(colorText); - else if (allowed > 0) - tvDest.setTextColor(colorOn); - else - tvDest.setTextColor(colorOff); - - llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE); - if (connections > 0) - tvConnections.setText(context.getString(R.string.msg_count, connections)); - - if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L) - tvTraffic.setText(context.getString(R.string.msg_gb, - (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0), - (received > 0 ? received / (1024 * 1024 * 1024f) : 0))); - else if (sent > 1204 * 1024L || received > 1024 * 1024L) - tvTraffic.setText(context.getString(R.string.msg_mb, - (sent > 0 ? sent / (1024 * 1024f) : 0), - (received > 0 ? received / (1024 * 1024f) : 0))); - else - tvTraffic.setText(context.getString(R.string.msg_kb, - (sent > 0 ? sent / 1024f : 0), - (received > 0 ? received / 1024f : 0))); - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterLog.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterLog.java deleted file mode 100644 index 892bf79..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/AdapterLog.java +++ /dev/null @@ -1,370 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.Context; -import android.content.SharedPreferences; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.database.Cursor; -import android.graphics.drawable.Drawable; -import android.net.Uri; -import android.os.AsyncTask; -import android.os.Build; -import android.text.TextUtils; -import android.util.Log; -import android.util.TypedValue; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CursorAdapter; -import android.widget.ImageView; -import android.widget.TextView; - -import androidx.core.graphics.drawable.DrawableCompat; -import androidx.core.view.ViewCompat; -import androidx.preference.PreferenceManager; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.text.SimpleDateFormat; -import java.util.List; - -public class AdapterLog extends CursorAdapter { - private static String TAG = "NetGuard.Log"; - - private boolean resolve; - private boolean organization; - private int colTime; - private int colVersion; - private int colProtocol; - private int colFlags; - private int colSAddr; - private int colSPort; - private int colDAddr; - private int colDPort; - private int colDName; - private int colUid; - private int colData; - private int colAllowed; - private int colConnection; - private int colInteractive; - private int colorOn; - private int colorOff; - private int iconSize; - private InetAddress dns1 = null; - private InetAddress dns2 = null; - private InetAddress vpn4 = null; - private InetAddress vpn6 = null; - - public AdapterLog(Context context, Cursor cursor, boolean resolve, boolean organization) { - super(context, cursor, 0); - this.resolve = resolve; - this.organization = organization; - colTime = cursor.getColumnIndex("time"); - colVersion = cursor.getColumnIndex("version"); - colProtocol = cursor.getColumnIndex("protocol"); - colFlags = cursor.getColumnIndex("flags"); - colSAddr = cursor.getColumnIndex("saddr"); - colSPort = cursor.getColumnIndex("sport"); - colDAddr = cursor.getColumnIndex("daddr"); - colDPort = cursor.getColumnIndex("dport"); - colDName = cursor.getColumnIndex("dname"); - colUid = cursor.getColumnIndex("uid"); - colData = cursor.getColumnIndex("data"); - colAllowed = cursor.getColumnIndex("allowed"); - colConnection = cursor.getColumnIndex("connection"); - colInteractive = cursor.getColumnIndex("interactive"); - - TypedValue tv = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.colorOn, tv, true); - colorOn = tv.data; - context.getTheme().resolveAttribute(R.attr.colorOff, tv, true); - colorOff = tv.data; - - iconSize = Util.dips2pixels(24, context); - - try { - List lstDns = ServiceSinkhole.getDns(context); - dns1 = (lstDns.size() > 0 ? lstDns.get(0) : null); - dns2 = (lstDns.size() > 1 ? lstDns.get(1) : null); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); - vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); - } catch (UnknownHostException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - - public void setResolve(boolean resolve) { - this.resolve = resolve; - } - - public void setOrganization(boolean organization) { - this.organization = organization; - } - - @Override - public View newView(Context context, Cursor cursor, ViewGroup parent) { - return LayoutInflater.from(context).inflate(R.layout.log, parent, false); - } - - @Override - public void bindView(final View view, final Context context, final Cursor cursor) { - // Get values - long time = cursor.getLong(colTime); - int version = (cursor.isNull(colVersion) ? -1 : cursor.getInt(colVersion)); - int protocol = (cursor.isNull(colProtocol) ? -1 : cursor.getInt(colProtocol)); - String flags = cursor.getString(colFlags); - String saddr = cursor.getString(colSAddr); - int sport = (cursor.isNull(colSPort) ? -1 : cursor.getInt(colSPort)); - String daddr = cursor.getString(colDAddr); - int dport = (cursor.isNull(colDPort) ? -1 : cursor.getInt(colDPort)); - String dname = (cursor.isNull(colDName) ? null : cursor.getString(colDName)); - int uid = (cursor.isNull(colUid) ? -1 : cursor.getInt(colUid)); - String data = cursor.getString(colData); - int allowed = (cursor.isNull(colAllowed) ? -1 : cursor.getInt(colAllowed)); - int connection = (cursor.isNull(colConnection) ? -1 : cursor.getInt(colConnection)); - int interactive = (cursor.isNull(colInteractive) ? -1 : cursor.getInt(colInteractive)); - - // Get views - TextView tvTime = view.findViewById(R.id.tvTime); - TextView tvProtocol = view.findViewById(R.id.tvProtocol); - TextView tvFlags = view.findViewById(R.id.tvFlags); - TextView tvSAddr = view.findViewById(R.id.tvSAddr); - TextView tvSPort = view.findViewById(R.id.tvSPort); - final TextView tvDaddr = view.findViewById(R.id.tvDAddr); - TextView tvDPort = view.findViewById(R.id.tvDPort); - final TextView tvOrganization = view.findViewById(R.id.tvOrganization); - final ImageView ivIcon = view.findViewById(R.id.ivIcon); - TextView tvUid = view.findViewById(R.id.tvUid); - TextView tvData = view.findViewById(R.id.tvData); - ImageView ivConnection = view.findViewById(R.id.ivConnection); - ImageView ivInteractive = view.findViewById(R.id.ivInteractive); - - // Show time - tvTime.setText(new SimpleDateFormat("HH:mm:ss").format(time)); - - // Show connection type - if (connection <= 0) - ivConnection.setImageResource(allowed > 0 ? R.drawable.host_allowed : R.drawable.host_blocked); - else { - if (allowed > 0) - ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_on : R.drawable.other_on); - else - ivConnection.setImageResource(connection == 1 ? R.drawable.wifi_off : R.drawable.other_off); - } - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrap = DrawableCompat.wrap(ivConnection.getDrawable()); - DrawableCompat.setTint(wrap, allowed > 0 ? colorOn : colorOff); - } - - // Show if screen on - if (interactive <= 0) - ivInteractive.setImageDrawable(null); - else { - ivInteractive.setImageResource(R.drawable.screen_on); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - Drawable wrap = DrawableCompat.wrap(ivInteractive.getDrawable()); - DrawableCompat.setTint(wrap, colorOn); - } - } - - // Show protocol name - tvProtocol.setText(Util.getProtocolName(protocol, version, false)); - - // SHow TCP flags - tvFlags.setText(flags); - tvFlags.setVisibility(TextUtils.isEmpty(flags) ? View.GONE : View.VISIBLE); - - // Show source and destination port - if (protocol == 6 || protocol == 17) { - tvSPort.setText(sport < 0 ? "" : getKnownPort(sport)); - tvDPort.setText(dport < 0 ? "" : getKnownPort(dport)); - } else { - tvSPort.setText(sport < 0 ? "" : Integer.toString(sport)); - tvDPort.setText(dport < 0 ? "" : Integer.toString(dport)); - } - - // Application icon - ApplicationInfo info = null; - PackageManager pm = context.getPackageManager(); - String[] pkg = pm.getPackagesForUid(uid); - if (pkg != null && pkg.length > 0) - try { - info = pm.getApplicationInfo(pkg[0], 0); - } catch (PackageManager.NameNotFoundException ignored) { - } - - if (info == null) - ivIcon.setImageDrawable(null); - else { - if (info.icon <= 0) - ivIcon.setImageResource(android.R.drawable.sym_def_app_icon); - else { - Uri uri = Uri.parse("android.resource://" + info.packageName + "/" + info.icon); - GlideApp.with(context) - .load(uri) - //.diskCacheStrategy(DiskCacheStrategy.NONE) - //.skipMemoryCache(true) - .override(iconSize, iconSize) - .into(ivIcon); - } - } - - boolean we = (android.os.Process.myUid() == uid); - - // https://android.googlesource.com/platform/system/core/+/master/include/private/android_filesystem_config.h - uid = uid % 100000; // strip off user ID - if (uid == -1) - tvUid.setText(""); - else if (uid == 0) - tvUid.setText(context.getString(R.string.title_root)); - else if (uid == 9999) - tvUid.setText("-"); // nobody - else - tvUid.setText(Integer.toString(uid)); - - // Show source address - tvSAddr.setText(getKnownAddress(saddr)); - - // Show destination address - if (!we && resolve && !isKnownAddress(daddr)) - if (dname == null) { - tvDaddr.setText(daddr); - new AsyncTask() { - @Override - protected void onPreExecute() { - ViewCompat.setHasTransientState(tvDaddr, true); - } - - @Override - protected String doInBackground(String... args) { - try { - return InetAddress.getByName(args[0]).getHostName(); - } catch (UnknownHostException ignored) { - return args[0]; - } - } - - @Override - protected void onPostExecute(String name) { - tvDaddr.setText(">" + name); - ViewCompat.setHasTransientState(tvDaddr, false); - } - }.execute(daddr); - } else - tvDaddr.setText(dname); - else - tvDaddr.setText(getKnownAddress(daddr)); - - // Show organization - tvOrganization.setVisibility(View.GONE); - if (!we && organization) { - if (!isKnownAddress(daddr)) - new AsyncTask() { - @Override - protected void onPreExecute() { - ViewCompat.setHasTransientState(tvOrganization, true); - } - - @Override - protected String doInBackground(String... args) { - try { - return Util.getOrganization(args[0]); - } catch (Throwable ex) { - Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - return null; - } - } - - @Override - protected void onPostExecute(String organization) { - if (organization != null) { - tvOrganization.setText(organization); - tvOrganization.setVisibility(View.VISIBLE); - } - ViewCompat.setHasTransientState(tvOrganization, false); - } - }.execute(daddr); - } - - // Show extra data - if (TextUtils.isEmpty(data)) { - tvData.setText(""); - tvData.setVisibility(View.GONE); - } else { - tvData.setText(data); - tvData.setVisibility(View.VISIBLE); - } - } - - public boolean isKnownAddress(String addr) { - try { - InetAddress a = InetAddress.getByName(addr); - if (a.equals(dns1) || a.equals(dns2) || a.equals(vpn4) || a.equals(vpn6)) - return true; - } catch (UnknownHostException ignored) { - } - return false; - } - - private String getKnownAddress(String addr) { - try { - InetAddress a = InetAddress.getByName(addr); - if (a.equals(dns1)) - return "dns1"; - if (a.equals(dns2)) - return "dns2"; - if (a.equals(vpn4) || a.equals(vpn6)) - return "vpn"; - } catch (UnknownHostException ignored) { - } - return addr; - } - - private String getKnownPort(int port) { - // https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Well-known_ports - switch (port) { - case 7: - return "echo"; - case 25: - return "smtp"; - case 53: - return "dns"; - case 80: - return "http"; - case 110: - return "pop3"; - case 143: - return "imap"; - case 443: - return "https"; - case 465: - return "smtps"; - case 993: - return "imaps"; - case 995: - return "pop3s"; - default: - return Integer.toString(port); - } - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ApplicationEx.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ApplicationEx.java deleted file mode 100644 index 3b7e0da..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ApplicationEx.java +++ /dev/null @@ -1,78 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.annotation.TargetApi; -import android.app.Application; -import android.app.Notification; -import android.app.NotificationChannel; -import android.app.NotificationManager; -import android.content.Context; -import android.os.Build; -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(); - Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this)); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - createNotificationChannels(); - - mPrevHandler = Thread.getDefaultUncaughtExceptionHandler(); - Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { - @Override - public void uncaughtException(Thread thread, Throwable ex) { - if (Util.ownFault(ApplicationEx.this, ex) - && Util.isPlayStoreInstall(ApplicationEx.this)) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - mPrevHandler.uncaughtException(thread, ex); - } else { - Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - System.exit(1); - } - } - }); - } - - @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); - foreground.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT); - nm.createNotificationChannel(foreground); - - NotificationChannel notify = new NotificationChannel("notify", getString(R.string.channel_notify), NotificationManager.IMPORTANCE_DEFAULT); - notify.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT); - notify.setBypassDnd(true); - nm.createNotificationChannel(notify); - - NotificationChannel access = new NotificationChannel("access", getString(R.string.channel_access), NotificationManager.IMPORTANCE_DEFAULT); - access.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT); - access.setBypassDnd(true); - nm.createNotificationChannel(access); - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/DatabaseHelper.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/DatabaseHelper.java deleted file mode 100644 index 47c0b9a..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/DatabaseHelper.java +++ /dev/null @@ -1,1164 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.ContentValues; -import android.content.Context; -import android.content.SharedPreferences; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteDoneException; -import android.database.sqlite.SQLiteOpenHelper; -import android.os.Handler; -import android.os.HandlerThread; -import android.os.Message; -import android.util.Log; - -import androidx.preference.PreferenceManager; - -import java.io.File; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -public class DatabaseHelper extends SQLiteOpenHelper { - private static final String TAG = "NetGuard.Database"; - - private static final String DB_NAME = "Netguard"; - private static final int DB_VERSION = 21; - - private static boolean once = true; - private static List logChangedListeners = new ArrayList<>(); - private static List accessChangedListeners = new ArrayList<>(); - private static List forwardChangedListeners = new ArrayList<>(); - - private static HandlerThread hthread = null; - private static Handler handler = null; - - private static final Map mapUidHosts = new HashMap<>(); - - private final static int MSG_LOG = 1; - private final static int MSG_ACCESS = 2; - private final static int MSG_FORWARD = 3; - - private SharedPreferences prefs; - private ReentrantReadWriteLock lock = new ReentrantReadWriteLock(true); - - static { - hthread = new HandlerThread("DatabaseHelper"); - hthread.start(); - handler = new Handler(hthread.getLooper()) { - @Override - public void handleMessage(Message msg) { - handleChangedNotification(msg); - } - }; - } - - private static DatabaseHelper dh = null; - - public static DatabaseHelper getInstance(Context context) { - if (dh == null) - dh = new DatabaseHelper(context.getApplicationContext()); - return dh; - } - - public static void clearCache() { - synchronized (mapUidHosts) { - mapUidHosts.clear(); - } - } - - @Override - public void close() { - Log.w(TAG, "Database is being closed"); - } - - private DatabaseHelper(Context context) { - super(context, DB_NAME, null, DB_VERSION); - prefs = PreferenceManager.getDefaultSharedPreferences(context); - - if (!once) { - once = true; - - File dbfile = context.getDatabasePath(DB_NAME); - if (dbfile.exists()) { - Log.w(TAG, "Deleting " + dbfile); - dbfile.delete(); - } - - File dbjournal = context.getDatabasePath(DB_NAME + "-journal"); - if (dbjournal.exists()) { - Log.w(TAG, "Deleting " + dbjournal); - dbjournal.delete(); - } - } - } - - @Override - public void onCreate(SQLiteDatabase db) { - Log.i(TAG, "Creating database " + DB_NAME + " version " + DB_VERSION); - createTableLog(db); - createTableAccess(db); - createTableDns(db); - createTableForward(db); - createTableApp(db); - } - - @Override - public void onConfigure(SQLiteDatabase db) { - db.enableWriteAheadLogging(); - super.onConfigure(db); - } - - private void createTableLog(SQLiteDatabase db) { - Log.i(TAG, "Creating log table"); - db.execSQL("CREATE TABLE log (" + - " ID INTEGER PRIMARY KEY AUTOINCREMENT" + - ", time INTEGER NOT NULL" + - ", version INTEGER" + - ", protocol INTEGER" + - ", flags TEXT" + - ", saddr TEXT" + - ", sport INTEGER" + - ", daddr TEXT" + - ", dport INTEGER" + - ", dname TEXT" + - ", uid INTEGER" + - ", data TEXT" + - ", allowed INTEGER" + - ", connection INTEGER" + - ", interactive INTEGER" + - ");"); - db.execSQL("CREATE INDEX idx_log_time ON log(time)"); - db.execSQL("CREATE INDEX idx_log_dest ON log(daddr)"); - db.execSQL("CREATE INDEX idx_log_dname ON log(dname)"); - db.execSQL("CREATE INDEX idx_log_dport ON log(dport)"); - db.execSQL("CREATE INDEX idx_log_uid ON log(uid)"); - } - - private void createTableAccess(SQLiteDatabase db) { - Log.i(TAG, "Creating access table"); - db.execSQL("CREATE TABLE access (" + - " ID INTEGER PRIMARY KEY AUTOINCREMENT" + - ", uid INTEGER NOT NULL" + - ", version INTEGER NOT NULL" + - ", protocol INTEGER NOT NULL" + - ", daddr TEXT NOT NULL" + - ", dport INTEGER NOT NULL" + - ", time INTEGER NOT NULL" + - ", allowed INTEGER" + - ", block INTEGER NOT NULL" + - ", sent INTEGER" + - ", received INTEGER" + - ", connections INTEGER" + - ");"); - db.execSQL("CREATE UNIQUE INDEX idx_access ON access(uid, version, protocol, daddr, dport)"); - db.execSQL("CREATE INDEX idx_access_daddr ON access(daddr)"); - db.execSQL("CREATE INDEX idx_access_block ON access(block)"); - } - - private void createTableDns(SQLiteDatabase db) { - Log.i(TAG, "Creating dns table"); - db.execSQL("CREATE TABLE dns (" + - " ID INTEGER PRIMARY KEY AUTOINCREMENT" + - ", time INTEGER NOT NULL" + - ", qname TEXT NOT NULL" + - ", aname TEXT NOT NULL" + - ", resource TEXT NOT NULL" + - ", ttl INTEGER" + - ");"); - db.execSQL("CREATE UNIQUE INDEX idx_dns ON dns(qname, aname, resource)"); - db.execSQL("CREATE INDEX idx_dns_resource ON dns(resource)"); - } - - private void createTableForward(SQLiteDatabase db) { - Log.i(TAG, "Creating forward table"); - db.execSQL("CREATE TABLE forward (" + - " ID INTEGER PRIMARY KEY AUTOINCREMENT" + - ", protocol INTEGER NOT NULL" + - ", dport INTEGER NOT NULL" + - ", raddr TEXT NOT NULL" + - ", rport INTEGER NOT NULL" + - ", ruid INTEGER NOT NULL" + - ");"); - db.execSQL("CREATE UNIQUE INDEX idx_forward ON forward(protocol, dport)"); - } - - private void createTableApp(SQLiteDatabase db) { - Log.i(TAG, "Creating app table"); - db.execSQL("CREATE TABLE app (" + - " ID INTEGER PRIMARY KEY AUTOINCREMENT" + - ", package TEXT" + - ", label TEXT" + - ", system INTEGER NOT NULL" + - ", internet INTEGER NOT NULL" + - ", enabled INTEGER NOT NULL" + - ");"); - db.execSQL("CREATE UNIQUE INDEX idx_package ON app(package)"); - } - - private boolean columnExists(SQLiteDatabase db, String table, String column) { - Cursor cursor = null; - try { - cursor = db.rawQuery("SELECT * FROM " + table + " LIMIT 0", null); - return (cursor.getColumnIndex(column) >= 0); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - return false; - } finally { - if (cursor != null) - cursor.close(); - } - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - Log.i(TAG, DB_NAME + " upgrading from version " + oldVersion + " to " + newVersion); - - db.beginTransaction(); - try { - if (oldVersion < 2) { - if (!columnExists(db, "log", "version")) - db.execSQL("ALTER TABLE log ADD COLUMN version INTEGER"); - if (!columnExists(db, "log", "protocol")) - db.execSQL("ALTER TABLE log ADD COLUMN protocol INTEGER"); - if (!columnExists(db, "log", "uid")) - db.execSQL("ALTER TABLE log ADD COLUMN uid INTEGER"); - oldVersion = 2; - } - if (oldVersion < 3) { - if (!columnExists(db, "log", "port")) - db.execSQL("ALTER TABLE log ADD COLUMN port INTEGER"); - if (!columnExists(db, "log", "flags")) - db.execSQL("ALTER TABLE log ADD COLUMN flags TEXT"); - oldVersion = 3; - } - if (oldVersion < 4) { - if (!columnExists(db, "log", "connection")) - db.execSQL("ALTER TABLE log ADD COLUMN connection INTEGER"); - oldVersion = 4; - } - if (oldVersion < 5) { - if (!columnExists(db, "log", "interactive")) - db.execSQL("ALTER TABLE log ADD COLUMN interactive INTEGER"); - oldVersion = 5; - } - if (oldVersion < 6) { - if (!columnExists(db, "log", "allowed")) - db.execSQL("ALTER TABLE log ADD COLUMN allowed INTEGER"); - oldVersion = 6; - } - if (oldVersion < 7) { - db.execSQL("DROP TABLE log"); - createTableLog(db); - oldVersion = 8; - } - if (oldVersion < 8) { - if (!columnExists(db, "log", "data")) - db.execSQL("ALTER TABLE log ADD COLUMN data TEXT"); - db.execSQL("DROP INDEX idx_log_source"); - db.execSQL("DROP INDEX idx_log_dest"); - db.execSQL("CREATE INDEX idx_log_source ON log(saddr)"); - db.execSQL("CREATE INDEX idx_log_dest ON log(daddr)"); - db.execSQL("CREATE INDEX IF NOT EXISTS idx_log_uid ON log(uid)"); - oldVersion = 8; - } - if (oldVersion < 9) { - createTableAccess(db); - oldVersion = 9; - } - if (oldVersion < 10) { - db.execSQL("DROP TABLE log"); - db.execSQL("DROP TABLE access"); - createTableLog(db); - createTableAccess(db); - oldVersion = 10; - } - if (oldVersion < 12) { - db.execSQL("DROP TABLE access"); - createTableAccess(db); - oldVersion = 12; - } - if (oldVersion < 13) { - db.execSQL("CREATE INDEX IF NOT EXISTS idx_log_dport ON log(dport)"); - db.execSQL("CREATE INDEX IF NOT EXISTS idx_log_dname ON log(dname)"); - oldVersion = 13; - } - if (oldVersion < 14) { - createTableDns(db); - oldVersion = 14; - } - if (oldVersion < 15) { - db.execSQL("DROP TABLE access"); - createTableAccess(db); - oldVersion = 15; - } - if (oldVersion < 16) { - createTableForward(db); - oldVersion = 16; - } - if (oldVersion < 17) { - if (!columnExists(db, "access", "sent")) - db.execSQL("ALTER TABLE access ADD COLUMN sent INTEGER"); - if (!columnExists(db, "access", "received")) - db.execSQL("ALTER TABLE access ADD COLUMN received INTEGER"); - oldVersion = 17; - } - if (oldVersion < 18) { - db.execSQL("CREATE INDEX IF NOT EXISTS idx_access_block ON access(block)"); - db.execSQL("DROP INDEX idx_dns"); - db.execSQL("CREATE UNIQUE INDEX IF NOT EXISTS idx_dns ON dns(qname, aname, resource)"); - db.execSQL("CREATE INDEX IF NOT EXISTS idx_dns_resource ON dns(resource)"); - oldVersion = 18; - } - if (oldVersion < 19) { - if (!columnExists(db, "access", "connections")) - db.execSQL("ALTER TABLE access ADD COLUMN connections INTEGER"); - oldVersion = 19; - } - if (oldVersion < 20) { - db.execSQL("CREATE INDEX IF NOT EXISTS idx_access_daddr ON access(daddr)"); - oldVersion = 20; - } - if (oldVersion < 21) { - createTableApp(db); - oldVersion = 21; - } - - if (oldVersion == DB_VERSION) { - db.setVersion(oldVersion); - db.setTransactionSuccessful(); - Log.i(TAG, DB_NAME + " upgraded to " + DB_VERSION); - } else - throw new IllegalArgumentException(DB_NAME + " upgraded to " + oldVersion + " but required " + DB_VERSION); - - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } finally { - db.endTransaction(); - } - } - - // Log - - public void insertLog(Packet packet, String dname, int connection, boolean interactive) { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - ContentValues cv = new ContentValues(); - cv.put("time", packet.time); - cv.put("version", packet.version); - - if (packet.protocol < 0) - cv.putNull("protocol"); - else - cv.put("protocol", packet.protocol); - - cv.put("flags", packet.flags); - - cv.put("saddr", packet.saddr); - if (packet.sport < 0) - cv.putNull("sport"); - else - cv.put("sport", packet.sport); - - cv.put("daddr", packet.daddr); - if (packet.dport < 0) - cv.putNull("dport"); - else - cv.put("dport", packet.dport); - - if (dname == null) - cv.putNull("dname"); - else - cv.put("dname", dname); - - cv.put("data", packet.data); - - if (packet.uid < 0) - cv.putNull("uid"); - else - cv.put("uid", packet.uid); - - cv.put("allowed", packet.allowed ? 1 : 0); - - cv.put("connection", connection); - cv.put("interactive", interactive ? 1 : 0); - - if (db.insert("log", null, cv) == -1) - Log.e(TAG, "Insert log failed"); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - - notifyLogChanged(); - } - - public void clearLog(int uid) { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - if (uid < 0) - db.delete("log", null, new String[]{}); - else - db.delete("log", "uid = ?", new String[]{Integer.toString(uid)}); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - - db.execSQL("VACUUM"); - } finally { - lock.writeLock().unlock(); - } - - notifyLogChanged(); - } - - public void cleanupLog(long time) { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - // There an index on time - int rows = db.delete("log", "time < ?", new String[]{Long.toString(time)}); - Log.i(TAG, "Cleanup log" + - " before=" + SimpleDateFormat.getDateTimeInstance().format(new Date(time)) + - " rows=" + rows); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - } - - public Cursor getLog(boolean udp, boolean tcp, boolean other, boolean allowed, boolean blocked) { - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - // There is an index on time - // There is no index on protocol/allowed for write performance - String query = "SELECT ID AS _id, *"; - query += " FROM log"; - query += " WHERE (0 = 1"; - if (udp) - query += " OR protocol = 17"; - if (tcp) - query += " OR protocol = 6"; - if (other) - query += " OR (protocol <> 6 AND protocol <> 17)"; - query += ") AND (0 = 1"; - if (allowed) - query += " OR allowed = 1"; - if (blocked) - query += " OR allowed = 0"; - query += ")"; - query += " ORDER BY time DESC"; - return db.rawQuery(query, new String[]{}); - } finally { - lock.readLock().unlock(); - } - } - - public Cursor searchLog(String find) { - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - // There is an index on daddr, dname, dport and uid - String query = "SELECT ID AS _id, *"; - query += " FROM log"; - query += " WHERE daddr LIKE ? OR dname LIKE ? OR dport = ? OR uid = ?"; - query += " ORDER BY time DESC"; - return db.rawQuery(query, new String[]{"%" + find + "%", "%" + find + "%", find, find}); - } finally { - lock.readLock().unlock(); - } - } - - // Access - - public boolean updateAccess(Packet packet, String dname, int block) { - int rows; - - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - ContentValues cv = new ContentValues(); - cv.put("time", packet.time); - cv.put("allowed", packet.allowed ? 1 : 0); - if (block >= 0) - cv.put("block", block); - - // There is a segmented index on uid, version, protocol, daddr and dport - rows = db.update("access", cv, "uid = ? AND version = ? AND protocol = ? AND daddr = ? AND dport = ?", - new String[]{ - Integer.toString(packet.uid), - Integer.toString(packet.version), - Integer.toString(packet.protocol), - dname == null ? packet.daddr : dname, - Integer.toString(packet.dport)}); - - if (rows == 0) { - cv.put("uid", packet.uid); - cv.put("version", packet.version); - cv.put("protocol", packet.protocol); - cv.put("daddr", dname == null ? packet.daddr : dname); - cv.put("dport", packet.dport); - if (block < 0) - cv.put("block", block); - - if (db.insert("access", null, cv) == -1) - Log.e(TAG, "Insert access failed"); - } else if (rows != 1) - Log.e(TAG, "Update access failed rows=" + rows); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - - notifyAccessChanged(); - return (rows == 0); - } - - public void updateUsage(Usage usage, String dname) { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - // There is a segmented index on uid, version, protocol, daddr and dport - String selection = "uid = ? AND version = ? AND protocol = ? AND daddr = ? AND dport = ?"; - String[] selectionArgs = new String[]{ - Integer.toString(usage.Uid), - Integer.toString(usage.Version), - Integer.toString(usage.Protocol), - dname == null ? usage.DAddr : dname, - Integer.toString(usage.DPort) - }; - - try (Cursor cursor = db.query("access", new String[]{"sent", "received", "connections"}, selection, selectionArgs, null, null, null)) { - long sent = 0; - long received = 0; - int connections = 0; - int colSent = cursor.getColumnIndex("sent"); - int colReceived = cursor.getColumnIndex("received"); - int colConnections = cursor.getColumnIndex("connections"); - if (cursor.moveToNext()) { - sent = cursor.isNull(colSent) ? 0 : cursor.getLong(colSent); - received = cursor.isNull(colReceived) ? 0 : cursor.getLong(colReceived); - connections = cursor.isNull(colConnections) ? 0 : cursor.getInt(colConnections); - } - - ContentValues cv = new ContentValues(); - cv.put("sent", sent + usage.Sent); - cv.put("received", received + usage.Received); - cv.put("connections", connections + 1); - - int rows = db.update("access", cv, selection, selectionArgs); - if (rows != 1) - Log.e(TAG, "Update usage failed rows=" + rows); - } - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - - notifyAccessChanged(); - } - - public void setAccess(long id, int block) { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - ContentValues cv = new ContentValues(); - cv.put("block", block); - cv.put("allowed", -1); - - if (db.update("access", cv, "ID = ?", new String[]{Long.toString(id)}) != 1) - Log.e(TAG, "Set access failed"); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - - notifyAccessChanged(); - } - - public void clearAccess() { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - db.delete("access", null, null); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - - notifyAccessChanged(); - } - - public void clearAccess(int uid, boolean keeprules) { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - // There is a segmented index on uid - // There is an index on block - if (keeprules) - db.delete("access", "uid = ? AND block < 0", new String[]{Integer.toString(uid)}); - else - db.delete("access", "uid = ?", new String[]{Integer.toString(uid)}); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - - notifyAccessChanged(); - } - - public void resetUsage(int uid) { - lock.writeLock().lock(); - try { - // There is a segmented index on uid - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - ContentValues cv = new ContentValues(); - cv.putNull("sent"); - cv.putNull("received"); - cv.putNull("connections"); - db.update("access", cv, - (uid < 0 ? null : "uid = ?"), - (uid < 0 ? null : new String[]{Integer.toString(uid)})); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - - notifyAccessChanged(); - } - - public Cursor getAccess(int uid) { - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - // There is a segmented index on uid - // There is no index on time for write performance - String query = "SELECT a.ID AS _id, a.*"; - query += ", (SELECT COUNT(DISTINCT d.qname) FROM dns d WHERE d.resource IN (SELECT d1.resource FROM dns d1 WHERE d1.qname = a.daddr)) count"; - query += " FROM access a"; - query += " WHERE a.uid = ?"; - query += " ORDER BY a.time DESC"; - query += " LIMIT 250"; - return db.rawQuery(query, new String[]{Integer.toString(uid)}); - } finally { - lock.readLock().unlock(); - } - } - - public Cursor getAccess() { - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - // There is a segmented index on uid - // There is an index on block - return db.query("access", null, "block >= 0", null, null, null, "uid"); - } finally { - lock.readLock().unlock(); - } - } - - public Cursor getAccessUnset(int uid, int limit, long since) { - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - // There is a segmented index on uid, block and daddr - // There is no index on allowed and time for write performance - String query = "SELECT MAX(time) AS time, daddr, allowed"; - query += " FROM access"; - query += " WHERE uid = ?"; - query += " AND block < 0"; - query += " AND time >= ?"; - query += " GROUP BY daddr, allowed"; - query += " ORDER BY time DESC"; - if (limit > 0) - query += " LIMIT " + limit; - return db.rawQuery(query, new String[]{Integer.toString(uid), Long.toString(since)}); - } finally { - lock.readLock().unlock(); - } - } - - public long getHostCount(int uid, boolean usecache) { - if (usecache) - synchronized (mapUidHosts) { - if (mapUidHosts.containsKey(uid)) - return mapUidHosts.get(uid); - } - - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - // There is a segmented index on uid - // There is an index on block - long hosts = db.compileStatement("SELECT COUNT(*) FROM access WHERE block >= 0 AND uid =" + uid).simpleQueryForLong(); - synchronized (mapUidHosts) { - mapUidHosts.put(uid, hosts); - } - return hosts; - } finally { - lock.readLock().unlock(); - } - } - - // DNS - - public boolean insertDns(ResourceRecord rr) { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - int ttl = rr.TTL; - - int min = Integer.parseInt(prefs.getString("ttl", "259200")); - if (ttl < min) - ttl = min; - - ContentValues cv = new ContentValues(); - cv.put("time", rr.Time); - cv.put("ttl", ttl * 1000L); - - int rows = db.update("dns", cv, "qname = ? AND aname = ? AND resource = ?", - new String[]{rr.QName, rr.AName, rr.Resource}); - - if (rows == 0) { - cv.put("qname", rr.QName); - cv.put("aname", rr.AName); - cv.put("resource", rr.Resource); - - if (db.insert("dns", null, cv) == -1) - Log.e(TAG, "Insert dns failed"); - else - rows = 1; - } else if (rows != 1) - Log.e(TAG, "Update dns failed rows=" + rows); - - db.setTransactionSuccessful(); - - return (rows > 0); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - } - - public void cleanupDns() { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - // There is no index on time for write performance - long now = new Date().getTime(); - db.execSQL("DELETE FROM dns WHERE time + ttl < " + now); - Log.i(TAG, "Cleanup DNS"); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - } - - public void clearDns() { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - db.delete("dns", null, new String[]{}); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - } - - public String getQName(int uid, String ip) { - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - // There is a segmented index on resource - String query = "SELECT d.qname"; - query += " FROM dns AS d"; - query += " WHERE d.resource = '" + ip.replace("'", "''") + "'"; - query += " ORDER BY d.qname"; - query += " LIMIT 1"; - // There is no way to known for sure which domain name an app used, so just pick the first one - return db.compileStatement(query).simpleQueryForString(); - } catch (SQLiteDoneException ignored) { - // Not found - return null; - } finally { - lock.readLock().unlock(); - } - } - - public Cursor getAlternateQNames(String qname) { - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - String query = "SELECT DISTINCT d2.qname"; - query += " FROM dns d1"; - query += " JOIN dns d2"; - query += " ON d2.resource = d1.resource AND d2.id <> d1.id"; - query += " WHERE d1.qname = ?"; - query += " ORDER BY d2.qname"; - return db.rawQuery(query, new String[]{qname}); - } finally { - lock.readLock().unlock(); - } - } - - public Cursor getDns() { - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - // There is an index on resource - // There is a segmented index on qname - String query = "SELECT ID AS _id, *"; - query += " FROM dns"; - query += " ORDER BY resource, qname"; - return db.rawQuery(query, new String[]{}); - } finally { - lock.readLock().unlock(); - } - } - - public Cursor getAccessDns(String dname) { - long now = new Date().getTime(); - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - - // There is a segmented index on dns.qname - // There is an index on access.daddr and access.block - String query = "SELECT a.uid, a.version, a.protocol, a.daddr, d.resource, a.dport, a.block, d.time, d.ttl"; - query += " FROM access AS a"; - query += " LEFT JOIN dns AS d"; - query += " ON d.qname = a.daddr"; - query += " WHERE a.block >= 0"; - query += " AND (d.time IS NULL OR d.time + d.ttl >= " + now + ")"; - if (dname != null) - query += " AND a.daddr = ?"; - - return db.rawQuery(query, dname == null ? new String[]{} : new String[]{dname}); - } finally { - lock.readLock().unlock(); - } - } - - // Forward - - public void addForward(int protocol, int dport, String raddr, int rport, int ruid) { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - ContentValues cv = new ContentValues(); - cv.put("protocol", protocol); - cv.put("dport", dport); - cv.put("raddr", raddr); - cv.put("rport", rport); - cv.put("ruid", ruid); - - if (db.insert("forward", null, cv) < 0) - Log.e(TAG, "Insert forward failed"); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - - notifyForwardChanged(); - } - - public void deleteForward() { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - db.delete("forward", null, null); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - - notifyForwardChanged(); - } - - public void deleteForward(int protocol, int dport) { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - db.delete("forward", "protocol = ? AND dport = ?", - new String[]{Integer.toString(protocol), Integer.toString(dport)}); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - - notifyForwardChanged(); - } - - public Cursor getForwarding() { - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - String query = "SELECT ID AS _id, *"; - query += " FROM forward"; - query += " ORDER BY dport"; - return db.rawQuery(query, new String[]{}); - } finally { - lock.readLock().unlock(); - } - } - - public void addApp(String packageName, String label, boolean system, boolean internet, boolean enabled) { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - ContentValues cv = new ContentValues(); - cv.put("package", packageName); - if (label == null) - cv.putNull("label"); - else - cv.put("label", label); - cv.put("system", system ? 1 : 0); - cv.put("internet", internet ? 1 : 0); - cv.put("enabled", enabled ? 1 : 0); - - if (db.insert("app", null, cv) < 0) - Log.e(TAG, "Insert app failed"); - - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - } - - public Cursor getApp(String packageName) { - lock.readLock().lock(); - try { - SQLiteDatabase db = this.getReadableDatabase(); - - // There is an index on package - String query = "SELECT * FROM app WHERE package = ?"; - - return db.rawQuery(query, new String[]{packageName}); - } finally { - lock.readLock().unlock(); - } - } - - public void clearApps() { - lock.writeLock().lock(); - try { - SQLiteDatabase db = this.getWritableDatabase(); - db.beginTransactionNonExclusive(); - try { - db.delete("app", null, null); - db.setTransactionSuccessful(); - } finally { - db.endTransaction(); - } - } finally { - lock.writeLock().unlock(); - } - } - - public void addLogChangedListener(LogChangedListener listener) { - logChangedListeners.add(listener); - } - - public void removeLogChangedListener(LogChangedListener listener) { - logChangedListeners.remove(listener); - } - - public void addAccessChangedListener(AccessChangedListener listener) { - accessChangedListeners.add(listener); - } - - public void removeAccessChangedListener(AccessChangedListener listener) { - accessChangedListeners.remove(listener); - } - - public void addForwardChangedListener(ForwardChangedListener listener) { - forwardChangedListeners.add(listener); - } - - public void removeForwardChangedListener(ForwardChangedListener listener) { - forwardChangedListeners.remove(listener); - } - - private void notifyLogChanged() { - Message msg = handler.obtainMessage(); - msg.what = MSG_LOG; - handler.sendMessage(msg); - } - - private void notifyAccessChanged() { - Message msg = handler.obtainMessage(); - msg.what = MSG_ACCESS; - handler.sendMessage(msg); - } - - private void notifyForwardChanged() { - Message msg = handler.obtainMessage(); - msg.what = MSG_FORWARD; - handler.sendMessage(msg); - } - - private static void handleChangedNotification(Message msg) { - // Batch notifications - try { - Thread.sleep(1000); - if (handler.hasMessages(msg.what)) - handler.removeMessages(msg.what); - } catch (InterruptedException ignored) { - } - - // Notify listeners - if (msg.what == MSG_LOG) { - for (LogChangedListener listener : logChangedListeners) - try { - listener.onChanged(); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - } else if (msg.what == MSG_ACCESS) { - for (AccessChangedListener listener : accessChangedListeners) - try { - listener.onChanged(); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - } else if (msg.what == MSG_FORWARD) { - for (ForwardChangedListener listener : forwardChangedListeners) - try { - listener.onChanged(); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - } - - public interface LogChangedListener { - void onChanged(); - } - - public interface AccessChangedListener { - void onChanged(); - } - - public interface ForwardChangedListener { - void onChanged(); - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/FragmentSettings.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/FragmentSettings.java deleted file mode 100644 index df8b3d3..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/FragmentSettings.java +++ /dev/null @@ -1,32 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.os.Bundle; -import android.preference.PreferenceFragment; - -public class FragmentSettings extends PreferenceFragment { - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.preferences); - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/GlideHelper.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/GlideHelper.java deleted file mode 100644 index a10561e..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/GlideHelper.java +++ /dev/null @@ -1,8 +0,0 @@ -package eu.faircode.netguard; - -import com.bumptech.glide.annotation.GlideModule; -import com.bumptech.glide.module.AppGlideModule; - -@GlideModule -public final class GlideHelper extends AppGlideModule { -} \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/IAB.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/IAB.java deleted file mode 100644 index 86b0dd1..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/IAB.java +++ /dev/null @@ -1,240 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.app.PendingIntent; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.os.IBinder; -import android.os.RemoteException; -import android.util.Log; - -import androidx.preference.PreferenceManager; - -import com.android.vending.billing.IInAppBillingService; - -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; -import java.util.List; - -public class IAB implements ServiceConnection { - private static final String TAG = "NetGuard.IAB"; - - private Context context; - private Delegate delegate; - private IInAppBillingService service = null; - - private static final int IAB_VERSION = 3; - - public interface Delegate { - void onReady(IAB iab); - } - - public IAB(Delegate delegate, Context context) { - this.context = context.getApplicationContext(); - this.delegate = delegate; - } - - public void bind() { - Log.i(TAG, "Bind"); - Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); - serviceIntent.setPackage("com.android.vending"); - context.bindService(serviceIntent, this, Context.BIND_AUTO_CREATE); - } - - public void unbind() { - if (service != null) { - Log.i(TAG, "Unbind"); - context.unbindService(this); - service = null; - } - } - - @Override - public void onServiceConnected(ComponentName name, IBinder binder) { - Log.i(TAG, "Connected"); - service = IInAppBillingService.Stub.asInterface(binder); - delegate.onReady(this); - } - - @Override - public void onServiceDisconnected(ComponentName name) { - Log.i(TAG, "Disconnected"); - service = null; - } - - public boolean isAvailable(String sku) throws RemoteException, JSONException { - // Get available SKUs - ArrayList skuList = new ArrayList<>(); - skuList.add(sku); - Bundle query = new Bundle(); - query.putStringArrayList("ITEM_ID_LIST", skuList); - Bundle bundle = service.getSkuDetails(IAB_VERSION, context.getPackageName(), "inapp", query); - Log.i(TAG, "getSkuDetails"); - Util.logBundle(bundle); - int response = (bundle == null ? -1 : bundle.getInt("RESPONSE_CODE", -1)); - Log.i(TAG, "Response=" + getResult(response)); - if (response != 0) - throw new IllegalArgumentException(getResult(response)); - - // Check available SKUs - boolean found = false; - ArrayList details = bundle.getStringArrayList("DETAILS_LIST"); - if (details != null) - for (String item : details) { - JSONObject object = new JSONObject(item); - if (sku.equals(object.getString("productId"))) { - found = true; - break; - } - } - Log.i(TAG, sku + "=" + found); - - return found; - } - - public void updatePurchases() throws RemoteException { - // Get purchases - List skus = new ArrayList<>(); - skus.addAll(getPurchases("inapp")); - skus.addAll(getPurchases("subs")); - - SharedPreferences prefs = context.getSharedPreferences("IAB", Context.MODE_PRIVATE); - SharedPreferences.Editor editor = prefs.edit(); - for (String product : prefs.getAll().keySet()) - if (!ActivityPro.SKU_DONATION.equals(product)) { - Log.i(TAG, "removing SKU=" + product); - editor.remove(product); - } - for (String sku : skus) { - Log.i(TAG, "adding SKU=" + sku); - editor.putBoolean(sku, true); - } - editor.apply(); - } - - public boolean isPurchased(String sku, String type) throws RemoteException { - return getPurchases(type).contains(sku); - } - - public List getPurchases(String type) throws RemoteException { - // Get purchases - Bundle bundle = service.getPurchases(IAB_VERSION, context.getPackageName(), type, null); - Log.i(TAG, "getPurchases"); - Util.logBundle(bundle); - int response = (bundle == null ? -1 : bundle.getInt("RESPONSE_CODE", -1)); - Log.i(TAG, "Response=" + getResult(response)); - if (response != 0) - throw new IllegalArgumentException(getResult(response)); - - ArrayList details = bundle.getStringArrayList("INAPP_PURCHASE_ITEM_LIST"); - return (details == null ? new ArrayList() : details); - } - - public PendingIntent getBuyIntent(String sku, boolean subscription) throws RemoteException { - if (service == null) - return null; - Bundle bundle = service.getBuyIntent(IAB_VERSION, context.getPackageName(), sku, subscription ? "subs" : "inapp", "netguard"); - Log.i(TAG, "getBuyIntent sku=" + sku + " subscription=" + subscription); - Util.logBundle(bundle); - int response = (bundle == null ? -1 : bundle.getInt("RESPONSE_CODE", -1)); - Log.i(TAG, "Response=" + getResult(response)); - if (response != 0) - throw new IllegalArgumentException(getResult(response)); - if (!bundle.containsKey("BUY_INTENT")) - throw new IllegalArgumentException("BUY_INTENT missing"); - return bundle.getParcelable("BUY_INTENT"); - } - - public static void setBought(String sku, Context context) { - Log.i(TAG, "Bought " + sku); - SharedPreferences prefs = context.getSharedPreferences("IAB", Context.MODE_PRIVATE); - prefs.edit().putBoolean(sku, true).apply(); - } - - public static boolean isPurchased(String sku, Context context) { - try { - if (Util.isDebuggable(context)) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - return !prefs.getBoolean("debug_iab", false); - } - - SharedPreferences prefs = context.getSharedPreferences("IAB", Context.MODE_PRIVATE); - if (ActivityPro.SKU_SUPPORT1.equals(sku) || ActivityPro.SKU_SUPPORT2.equals(sku)) - return prefs.getBoolean(sku, false); - - return (prefs.getBoolean(sku, false) || - prefs.getBoolean(ActivityPro.SKU_PRO1, false) || - prefs.getBoolean(ActivityPro.SKU_SUPPORT1, false) || - prefs.getBoolean(ActivityPro.SKU_SUPPORT2, false) || - prefs.getBoolean(ActivityPro.SKU_DONATION, false)); - } catch (SecurityException ignored) { - return false; - } - } - - public static boolean isPurchasedAny(Context context) { - try { - if (Util.isDebuggable(context)) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - return !(prefs.getBoolean("debug_iab", false)); - } - - SharedPreferences prefs = context.getSharedPreferences("IAB", Context.MODE_PRIVATE); - for (String key : prefs.getAll().keySet()) - if (prefs.getBoolean(key, false)) - return true; - return false; - } catch (SecurityException ignored) { - return false; - } - } - - public static String getResult(int responseCode) { - switch (responseCode) { - case 0: - return "OK"; - case 1: - return "USER_CANCELED"; - case 2: - return "SERVICE_UNAVAILABLE"; - case 3: - return "BILLING_UNAVAILABLE"; - case 4: - return "ITEM_UNAVAILABLE"; - case 5: - return "DEVELOPER_ERROR"; - case 6: - return "ERROR"; - case 7: - return "ITEM_ALREADY_OWNED"; - case 8: - return "ITEM_NOT_OWNED"; - default: - return Integer.toString(responseCode); - } - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ReceiverAutostart.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ReceiverAutostart.java deleted file mode 100644 index 75aad2a..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ReceiverAutostart.java +++ /dev/null @@ -1,132 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Build; -import android.util.Log; - -import androidx.preference.PreferenceManager; - -import java.util.Map; - -public class ReceiverAutostart extends BroadcastReceiver { - private static final String TAG = "NetGuard.Receiver"; - - @Override - public void onReceive(final Context context, Intent intent) { - Log.i(TAG, "Received " + intent); - Util.logExtras(intent); - - String action = (intent == null ? null : intent.getAction()); - if (Intent.ACTION_BOOT_COMPLETED.equals(action) || Intent.ACTION_MY_PACKAGE_REPLACED.equals(action)) - try { - // Upgrade settings - upgrade(true, context); - - // Start service - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - if (prefs.getBoolean("enabled", false)) - ServiceSinkhole.start("receiver", context); - else if (prefs.getBoolean("show_stats", false)) - ServiceSinkhole.run("receiver", context); - - if (Util.isInteractive(context)) - ServiceSinkhole.reloadStats("receiver", context); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - - public static void upgrade(boolean initialized, Context context) { - synchronized (context.getApplicationContext()) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - int oldVersion = prefs.getInt("version", -1); - int newVersion = Util.getSelfVersionCode(context); - if (oldVersion == newVersion) - return; - Log.i(TAG, "Upgrading from version " + oldVersion + " to " + newVersion); - - SharedPreferences.Editor editor = prefs.edit(); - - if (initialized) { - if (oldVersion < 38) { - Log.i(TAG, "Converting screen wifi/mobile"); - editor.putBoolean("screen_wifi", prefs.getBoolean("unused", false)); - editor.putBoolean("screen_other", prefs.getBoolean("unused", false)); - editor.remove("unused"); - - SharedPreferences unused = context.getSharedPreferences("unused", Context.MODE_PRIVATE); - SharedPreferences screen_wifi = context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE); - SharedPreferences screen_other = context.getSharedPreferences("screen_other", Context.MODE_PRIVATE); - - Map punused = unused.getAll(); - SharedPreferences.Editor edit_screen_wifi = screen_wifi.edit(); - SharedPreferences.Editor edit_screen_other = screen_other.edit(); - for (String key : punused.keySet()) { - edit_screen_wifi.putBoolean(key, (Boolean) punused.get(key)); - edit_screen_other.putBoolean(key, (Boolean) punused.get(key)); - } - edit_screen_wifi.apply(); - edit_screen_other.apply(); - - } else if (oldVersion <= 2017032112) - editor.remove("ip6"); - - } else { - Log.i(TAG, "Initializing sdk=" + Build.VERSION.SDK_INT); - editor.putBoolean("filter_udp", true); - editor.putBoolean("whitelist_wifi", false); - editor.putBoolean("whitelist_other", false); - if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) - editor.putBoolean("filter", true); // Optional - } - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) - editor.putBoolean("filter", true); // Mandatory - - if (!Util.canFilter(context)) { - editor.putBoolean("log_app", false); - editor.putBoolean("filter", false); - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - editor.remove("show_top"); - if ("data".equals(prefs.getString("sort", "name"))) - editor.remove("sort"); - } - - if (Util.isPlayStoreInstall(context)) { - editor.remove("update_check"); - editor.remove("use_hosts"); - editor.remove("hosts_url"); - } - - if (!Util.isDebuggable(context)) - editor.remove("loglevel"); - - editor.putInt("version", newVersion); - editor.apply(); - } - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ReceiverPackageRemoved.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ReceiverPackageRemoved.java deleted file mode 100644 index d8ebf9a..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ReceiverPackageRemoved.java +++ /dev/null @@ -1,50 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.util.Log; - -import androidx.core.app.NotificationManagerCompat; - -public class ReceiverPackageRemoved extends BroadcastReceiver { - private static final String TAG = "NetGuard.Receiver"; - - @Override - public void onReceive(final Context context, Intent intent) { - Log.i(TAG, "Received " + intent); - Util.logExtras(intent); - - String action = (intent == null ? null : intent.getAction()); - if (Intent.ACTION_PACKAGE_FULLY_REMOVED.equals(action)) { - int uid = intent.getIntExtra(Intent.EXTRA_UID, 0); - if (uid > 0) { - DatabaseHelper dh = DatabaseHelper.getInstance(context); - dh.clearLog(uid); - dh.clearAccess(uid, false); - - NotificationManagerCompat.from(context).cancel(uid); // installed notification - NotificationManagerCompat.from(context).cancel(uid + 10000); // access notification - } - } - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Rule.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Rule.java deleted file mode 100644 index e2e2b6e..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Rule.java +++ /dev/null @@ -1,453 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.content.Context; -import android.content.SharedPreferences; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.res.XmlResourceParser; -import android.database.Cursor; -import android.os.Build; -import android.os.Process; -import android.util.Log; - -import androidx.preference.PreferenceManager; - -import org.xmlpull.v1.XmlPullParser; - -import java.text.Collator; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -public class Rule { - private static final String TAG = "NetGuard.Rule"; - - public int uid; - public String packageName; - public int icon; - public String name; - public String version; - public boolean system; - public boolean internet; - public boolean enabled; - public boolean pkg = true; - - public boolean wifi_default = false; - public boolean other_default = false; - public boolean screen_wifi_default = false; - public boolean screen_other_default = false; - public boolean roaming_default = false; - - public boolean wifi_blocked = false; - public boolean other_blocked = false; - public boolean screen_wifi = false; - public boolean screen_other = false; - public boolean roaming = false; - public boolean lockdown = false; - - public boolean apply = true; - public boolean notify = true; - - public boolean relateduids = false; - public String[] related = null; - - public long hosts; - public boolean changed; - - public boolean expanded = false; - - private static List cachePackageInfo = null; - private static Map cacheLabel = new HashMap<>(); - private static Map cacheSystem = new HashMap<>(); - private static Map cacheInternet = new HashMap<>(); - private static Map cacheEnabled = new HashMap<>(); - - private static List getPackages(Context context) { - if (cachePackageInfo == null) { - PackageManager pm = context.getPackageManager(); - cachePackageInfo = pm.getInstalledPackages(0); - } - return new ArrayList<>(cachePackageInfo); - } - - private static String getLabel(PackageInfo info, Context context) { - if (!cacheLabel.containsKey(info)) { - PackageManager pm = context.getPackageManager(); - cacheLabel.put(info, info.applicationInfo.loadLabel(pm).toString()); - } - return cacheLabel.get(info); - } - - private static boolean isSystem(String packageName, Context context) { - if (!cacheSystem.containsKey(packageName)) - cacheSystem.put(packageName, Util.isSystem(packageName, context)); - return cacheSystem.get(packageName); - } - - private static boolean hasInternet(String packageName, Context context) { - if (!cacheInternet.containsKey(packageName)) - cacheInternet.put(packageName, Util.hasInternet(packageName, context)); - return cacheInternet.get(packageName); - } - - private static boolean isEnabled(PackageInfo info, Context context) { - if (!cacheEnabled.containsKey(info)) - cacheEnabled.put(info, Util.isEnabled(info, context)); - return cacheEnabled.get(info); - } - - public static void clearCache(Context context) { - Log.i(TAG, "Clearing cache"); - synchronized (context.getApplicationContext()) { - cachePackageInfo = null; - cacheLabel.clear(); - cacheSystem.clear(); - cacheInternet.clear(); - cacheEnabled.clear(); - } - - DatabaseHelper dh = DatabaseHelper.getInstance(context); - dh.clearApps(); - } - - private Rule(DatabaseHelper dh, PackageInfo info, Context context) { - this.uid = info.applicationInfo.uid; - this.packageName = info.packageName; - this.icon = info.applicationInfo.icon; - this.version = info.versionName; - if (info.applicationInfo.uid == 0) { - this.name = context.getString(R.string.title_root); - this.system = true; - this.internet = true; - this.enabled = true; - this.pkg = false; - } else if (info.applicationInfo.uid == 1013) { - this.name = context.getString(R.string.title_mediaserver); - this.system = true; - this.internet = true; - this.enabled = true; - this.pkg = false; - } else if (info.applicationInfo.uid == 1020) { - this.name = "MulticastDNSResponder"; - this.system = true; - this.internet = true; - this.enabled = true; - this.pkg = false; - } else if (info.applicationInfo.uid == 1021) { - this.name = context.getString(R.string.title_gpsdaemon); - this.system = true; - this.internet = true; - this.enabled = true; - this.pkg = false; - } else if (info.applicationInfo.uid == 1051) { - this.name = context.getString(R.string.title_dnsdaemon); - this.system = true; - this.internet = true; - this.enabled = true; - this.pkg = false; - } else if (info.applicationInfo.uid == 9999) { - this.name = context.getString(R.string.title_nobody); - this.system = true; - this.internet = true; - this.enabled = true; - this.pkg = false; - } else { - Cursor cursor = null; - try { - cursor = dh.getApp(this.packageName); - if (cursor.moveToNext()) { - this.name = cursor.getString(cursor.getColumnIndex("label")); - this.system = cursor.getInt(cursor.getColumnIndex("system")) > 0; - this.internet = cursor.getInt(cursor.getColumnIndex("internet")) > 0; - this.enabled = cursor.getInt(cursor.getColumnIndex("enabled")) > 0; - } else { - this.name = getLabel(info, context); - this.system = isSystem(info.packageName, context); - this.internet = hasInternet(info.packageName, context); - this.enabled = isEnabled(info, context); - - dh.addApp(this.packageName, this.name, this.system, this.internet, this.enabled); - } - } finally { - if (cursor != null) - cursor.close(); - } - } - } - - public static List getRules(final boolean all, Context context) { - synchronized (context.getApplicationContext()) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - SharedPreferences wifi = context.getSharedPreferences("wifi", Context.MODE_PRIVATE); - SharedPreferences other = context.getSharedPreferences("other", Context.MODE_PRIVATE); - SharedPreferences screen_wifi = context.getSharedPreferences("screen_wifi", Context.MODE_PRIVATE); - SharedPreferences screen_other = context.getSharedPreferences("screen_other", Context.MODE_PRIVATE); - SharedPreferences roaming = context.getSharedPreferences("roaming", Context.MODE_PRIVATE); - SharedPreferences lockdown = context.getSharedPreferences("lockdown", Context.MODE_PRIVATE); - SharedPreferences apply = context.getSharedPreferences("apply", Context.MODE_PRIVATE); - SharedPreferences notify = context.getSharedPreferences("notify", Context.MODE_PRIVATE); - - // Get settings - boolean default_wifi = prefs.getBoolean("whitelist_wifi", true); - boolean default_other = prefs.getBoolean("whitelist_other", true); - boolean default_screen_wifi = prefs.getBoolean("screen_wifi", false); - boolean default_screen_other = prefs.getBoolean("screen_other", false); - boolean default_roaming = prefs.getBoolean("whitelist_roaming", true); - - boolean manage_system = prefs.getBoolean("manage_system", false); - boolean screen_on = prefs.getBoolean("screen_on", true); - boolean show_user = prefs.getBoolean("show_user", true); - boolean show_system = prefs.getBoolean("show_system", false); - boolean show_nointernet = prefs.getBoolean("show_nointernet", true); - boolean show_disabled = prefs.getBoolean("show_disabled", true); - - default_screen_wifi = default_screen_wifi && screen_on; - default_screen_other = default_screen_other && screen_on; - - // Get predefined rules - Map pre_wifi_blocked = new HashMap<>(); - Map pre_other_blocked = new HashMap<>(); - Map pre_roaming = new HashMap<>(); - Map pre_related = new HashMap<>(); - Map pre_system = new HashMap<>(); - try { - XmlResourceParser xml = context.getResources().getXml(R.xml.predefined); - int eventType = xml.getEventType(); - while (eventType != XmlPullParser.END_DOCUMENT) { - if (eventType == XmlPullParser.START_TAG) - if ("wifi".equals(xml.getName())) { - String pkg = xml.getAttributeValue(null, "package"); - boolean pblocked = xml.getAttributeBooleanValue(null, "blocked", false); - pre_wifi_blocked.put(pkg, pblocked); - - } else if ("other".equals(xml.getName())) { - String pkg = xml.getAttributeValue(null, "package"); - boolean pblocked = xml.getAttributeBooleanValue(null, "blocked", false); - boolean proaming = xml.getAttributeBooleanValue(null, "roaming", default_roaming); - pre_other_blocked.put(pkg, pblocked); - pre_roaming.put(pkg, proaming); - - } else if ("relation".equals(xml.getName())) { - String pkg = xml.getAttributeValue(null, "package"); - String[] rel = xml.getAttributeValue(null, "related").split(","); - pre_related.put(pkg, rel); - - } else if ("type".equals(xml.getName())) { - String pkg = xml.getAttributeValue(null, "package"); - boolean system = xml.getAttributeBooleanValue(null, "system", true); - pre_system.put(pkg, system); - } - - - eventType = xml.next(); - } - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - // Build rule list - List listRules = new ArrayList<>(); - List listPI = getPackages(context); - - int userId = Process.myUid() / 100000; - - // Add root - PackageInfo root = new PackageInfo(); - root.packageName = "root"; - root.versionCode = Build.VERSION.SDK_INT; - root.versionName = Build.VERSION.RELEASE; - root.applicationInfo = new ApplicationInfo(); - root.applicationInfo.uid = 0; - root.applicationInfo.icon = 0; - listPI.add(root); - - // Add mediaserver - PackageInfo media = new PackageInfo(); - media.packageName = "android.media"; - media.versionCode = Build.VERSION.SDK_INT; - media.versionName = Build.VERSION.RELEASE; - media.applicationInfo = new ApplicationInfo(); - media.applicationInfo.uid = 1013 + userId * 100000; - media.applicationInfo.icon = 0; - listPI.add(media); - - // MulticastDNSResponder - PackageInfo mdr = new PackageInfo(); - mdr.packageName = "android.multicast"; - mdr.versionCode = Build.VERSION.SDK_INT; - mdr.versionName = Build.VERSION.RELEASE; - mdr.applicationInfo = new ApplicationInfo(); - mdr.applicationInfo.uid = 1020 + userId * 100000; - mdr.applicationInfo.icon = 0; - listPI.add(mdr); - - // Add GPS daemon - PackageInfo gps = new PackageInfo(); - gps.packageName = "android.gps"; - gps.versionCode = Build.VERSION.SDK_INT; - gps.versionName = Build.VERSION.RELEASE; - gps.applicationInfo = new ApplicationInfo(); - gps.applicationInfo.uid = 1021 + userId * 100000; - gps.applicationInfo.icon = 0; - listPI.add(gps); - - // Add DNS daemon - PackageInfo dns = new PackageInfo(); - dns.packageName = "android.dns"; - dns.versionCode = Build.VERSION.SDK_INT; - dns.versionName = Build.VERSION.RELEASE; - dns.applicationInfo = new ApplicationInfo(); - dns.applicationInfo.uid = 1051 + userId * 100000; - dns.applicationInfo.icon = 0; - listPI.add(dns); - - // Add nobody - PackageInfo nobody = new PackageInfo(); - nobody.packageName = "nobody"; - nobody.versionCode = Build.VERSION.SDK_INT; - nobody.versionName = Build.VERSION.RELEASE; - nobody.applicationInfo = new ApplicationInfo(); - nobody.applicationInfo.uid = 9999; - nobody.applicationInfo.icon = 0; - listPI.add(nobody); - - DatabaseHelper dh = DatabaseHelper.getInstance(context); - for (PackageInfo info : listPI) - try { - // Skip self - if (info.applicationInfo.uid == Process.myUid()) - continue; - - Rule rule = new Rule(dh, info, context); - - if (pre_system.containsKey(info.packageName)) - rule.system = pre_system.get(info.packageName); - if (info.applicationInfo.uid == Process.myUid()) - rule.system = true; - - if (all || - ((rule.system ? show_system : show_user) && - (show_nointernet || rule.internet) && - (show_disabled || rule.enabled))) { - - rule.wifi_default = (pre_wifi_blocked.containsKey(info.packageName) ? pre_wifi_blocked.get(info.packageName) : default_wifi); - rule.other_default = (pre_other_blocked.containsKey(info.packageName) ? pre_other_blocked.get(info.packageName) : default_other); - rule.screen_wifi_default = default_screen_wifi; - rule.screen_other_default = default_screen_other; - rule.roaming_default = (pre_roaming.containsKey(info.packageName) ? pre_roaming.get(info.packageName) : default_roaming); - - rule.wifi_blocked = (!(rule.system && !manage_system) && wifi.getBoolean(info.packageName, rule.wifi_default)); - rule.other_blocked = (!(rule.system && !manage_system) && other.getBoolean(info.packageName, rule.other_default)); - rule.screen_wifi = screen_wifi.getBoolean(info.packageName, rule.screen_wifi_default) && screen_on; - rule.screen_other = screen_other.getBoolean(info.packageName, rule.screen_other_default) && screen_on; - rule.roaming = roaming.getBoolean(info.packageName, rule.roaming_default); - rule.lockdown = lockdown.getBoolean(info.packageName, false); - - rule.apply = apply.getBoolean(info.packageName, true); - rule.notify = notify.getBoolean(info.packageName, true); - - // Related packages - List listPkg = new ArrayList<>(); - if (pre_related.containsKey(info.packageName)) - listPkg.addAll(Arrays.asList(pre_related.get(info.packageName))); - for (PackageInfo pi : listPI) - if (pi.applicationInfo.uid == rule.uid && !pi.packageName.equals(rule.packageName)) { - rule.relateduids = true; - listPkg.add(pi.packageName); - } - rule.related = listPkg.toArray(new String[0]); - - rule.hosts = dh.getHostCount(rule.uid, true); - - rule.updateChanged(default_wifi, default_other, default_roaming); - - listRules.add(rule); - } - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - // Sort rule list - final Collator collator = Collator.getInstance(Locale.getDefault()); - collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc - - String sort = prefs.getString("sort", "name"); - if ("uid".equals(sort)) - Collections.sort(listRules, new Comparator() { - @Override - public int compare(Rule rule, Rule other) { - if (rule.uid < other.uid) - return -1; - else if (rule.uid > other.uid) - return 1; - else { - int i = collator.compare(rule.name, other.name); - return (i == 0 ? rule.packageName.compareTo(other.packageName) : i); - } - } - }); - else - Collections.sort(listRules, new Comparator() { - @Override - public int compare(Rule rule, Rule other) { - if (all || rule.changed == other.changed) { - int i = collator.compare(rule.name, other.name); - return (i == 0 ? rule.packageName.compareTo(other.packageName) : i); - } - return (rule.changed ? -1 : 1); - } - }); - - return listRules; - } - } - - private void updateChanged(boolean default_wifi, boolean default_other, boolean default_roaming) { - changed = (wifi_blocked != default_wifi || - (other_blocked != default_other) || - (wifi_blocked && screen_wifi != screen_wifi_default) || - (other_blocked && screen_other != screen_other_default) || - ((!other_blocked || screen_other) && roaming != default_roaming) || - hosts > 0 || lockdown || !apply); - } - - public void updateChanged(Context context) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean screen_on = prefs.getBoolean("screen_on", false); - boolean default_wifi = prefs.getBoolean("whitelist_wifi", true) && screen_on; - boolean default_other = prefs.getBoolean("whitelist_other", true) && screen_on; - boolean default_roaming = prefs.getBoolean("whitelist_roaming", true); - updateChanged(default_wifi, default_other, default_roaming); - } - - @Override - public String toString() { - // This is used in the port forwarding dialog application selector - return this.name; - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceExternal.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceExternal.java deleted file mode 100644 index 3330548..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceExternal.java +++ /dev/null @@ -1,146 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.app.IntentService; -import android.app.Notification; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.util.Log; - -import androidx.core.app.NotificationCompat; -import androidx.preference.PreferenceManager; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.text.SimpleDateFormat; -import java.util.Date; - -public class ServiceExternal extends IntentService { - private static final String TAG = "NetGuard.External"; - private static final String ACTION_DOWNLOAD_HOSTS_FILE = "eu.faircode.netguard.DOWNLOAD_HOSTS_FILE"; - - // am startservice -a eu.faircode.netguard.DOWNLOAD_HOSTS_FILE - - public ServiceExternal() { - super(TAG); - } - - @Override - protected void onHandleIntent(Intent intent) { - try { - startForeground(ServiceSinkhole.NOTIFY_EXTERNAL, getForegroundNotification(this)); - - Log.i(TAG, "Received " + intent); - Util.logExtras(intent); - - if (ACTION_DOWNLOAD_HOSTS_FILE.equals(intent.getAction())) { - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - - String hosts_url = prefs.getString("hosts_url", null); - if ("https://www.netguard.me/hosts".equals(hosts_url)) - hosts_url = BuildConfig.HOSTS_FILE_URI; - - File tmp = new File(getFilesDir(), "hosts.tmp"); - File hosts = new File(getFilesDir(), "hosts.txt"); - - InputStream in = null; - OutputStream out = null; - URLConnection connection = null; - try { - URL url = new URL(hosts_url); - connection = url.openConnection(); - connection.connect(); - - if (connection instanceof HttpURLConnection) { - HttpURLConnection httpConnection = (HttpURLConnection) connection; - if (httpConnection.getResponseCode() != HttpURLConnection.HTTP_OK) - throw new IOException(httpConnection.getResponseCode() + " " + httpConnection.getResponseMessage()); - } - - int contentLength = connection.getContentLength(); - Log.i(TAG, "Content length=" + contentLength); - in = connection.getInputStream(); - out = new FileOutputStream(tmp); - - long size = 0; - byte buffer[] = new byte[4096]; - int bytes; - while ((bytes = in.read(buffer)) != -1) { - out.write(buffer, 0, bytes); - size += bytes; - } - - Log.i(TAG, "Downloaded size=" + size); - - if (hosts.exists()) - hosts.delete(); - tmp.renameTo(hosts); - - String last = SimpleDateFormat.getDateTimeInstance().format(new Date().getTime()); - prefs.edit().putString("hosts_last_download", last).apply(); - - ServiceSinkhole.reload("hosts file download", this, false); - - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - - if (tmp.exists()) - tmp.delete(); - } finally { - try { - if (out != null) - out.close(); - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - try { - if (in != null) - in.close(); - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - - if (connection instanceof HttpURLConnection) - ((HttpURLConnection) connection).disconnect(); - } - } - } finally { - stopForeground(true); - } - } - - private static Notification getForegroundNotification(Context context) { - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, "foreground"); - builder.setSmallIcon(R.drawable.ic_hourglass_empty_white_24dp); - builder.setPriority(NotificationCompat.PRIORITY_MIN); - builder.setCategory(NotificationCompat.CATEGORY_STATUS); - builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC); - builder.setContentTitle(context.getString(R.string.app_name)); - return builder.build(); - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileGraph.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileGraph.java deleted file mode 100644 index 30c38ca..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileGraph.java +++ /dev/null @@ -1,80 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - - -import android.annotation.TargetApi; -import android.content.SharedPreferences; -import android.graphics.drawable.Icon; -import android.os.Build; -import android.service.quicksettings.Tile; -import android.service.quicksettings.TileService; -import android.util.Log; -import android.widget.Toast; - -import androidx.preference.PreferenceManager; - -@TargetApi(Build.VERSION_CODES.N) -public class ServiceTileGraph extends TileService implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.TileGraph"; - - public void onStartListening() { - Log.i(TAG, "Start listening"); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.registerOnSharedPreferenceChangeListener(this); - update(); - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - if ("show_stats".equals(key)) - update(); - } - - private void update() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean stats = prefs.getBoolean("show_stats", false); - Tile tile = getQsTile(); - if (tile != null) { - tile.setState(stats ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); - tile.setIcon(Icon.createWithResource(this, stats ? R.drawable.ic_equalizer_white_24dp : R.drawable.ic_equalizer_white_24dp_60)); - tile.updateTile(); - } - } - - public void onStopListening() { - Log.i(TAG, "Stop listening"); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.unregisterOnSharedPreferenceChangeListener(this); - } - - public void onClick() { - Log.i(TAG, "Click"); - - // Check state - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean stats = !prefs.getBoolean("show_stats", false); - if (stats && !IAB.isPurchased(ActivityPro.SKU_SPEED, this)) - Toast.makeText(this, R.string.title_pro_feature, Toast.LENGTH_SHORT).show(); - else - prefs.edit().putBoolean("show_stats", stats).apply(); - ServiceSinkhole.reloadStats("tile", this); - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileLockdown.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileLockdown.java deleted file mode 100644 index 1aaffea..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/ServiceTileLockdown.java +++ /dev/null @@ -1,75 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - - -import android.annotation.TargetApi; -import android.content.SharedPreferences; -import android.graphics.drawable.Icon; -import android.os.Build; -import android.service.quicksettings.Tile; -import android.service.quicksettings.TileService; -import android.util.Log; - -import androidx.preference.PreferenceManager; - -@TargetApi(Build.VERSION_CODES.N) -public class ServiceTileLockdown extends TileService implements SharedPreferences.OnSharedPreferenceChangeListener { - private static final String TAG = "NetGuard.TileLockdown"; - - public void onStartListening() { - Log.i(TAG, "Start listening"); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.registerOnSharedPreferenceChangeListener(this); - update(); - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { - if ("lockdown".equals(key)) - update(); - } - - private void update() { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - boolean lockdown = prefs.getBoolean("lockdown", false); - Tile tile = getQsTile(); - if (tile != null) { - tile.setState(lockdown ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); - tile.setIcon(Icon.createWithResource(this, lockdown ? R.drawable.ic_lock_outline_white_24dp : R.drawable.ic_lock_outline_white_24dp_60)); - tile.updateTile(); - } - } - - public void onStopListening() { - Log.i(TAG, "Stop listening"); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.unregisterOnSharedPreferenceChangeListener(this); - } - - public void onClick() { - Log.i(TAG, "Click"); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - prefs.edit().putBoolean("lockdown", !prefs.getBoolean("lockdown", false)).apply(); - ServiceSinkhole.reload("tile", this, false); - WidgetLockdown.updateWidgets(this); - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Util.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Util.java deleted file mode 100644 index 1cae9fb..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/Util.java +++ /dev/null @@ -1,1075 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.Manifest; -import android.annotation.TargetApi; -import android.app.Activity; -import android.app.ActivityManager; -import android.app.ApplicationErrorReport; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.content.res.Resources; -import android.database.Cursor; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.net.ConnectivityManager; -import android.net.LinkProperties; -import android.net.Network; -import android.net.NetworkInfo; -import android.net.Uri; -import android.net.VpnService; -import android.net.wifi.WifiManager; -import android.os.AsyncTask; -import android.os.Build; -import android.os.Bundle; -import android.os.Debug; -import android.os.PowerManager; -import android.provider.Settings; -import android.telephony.TelephonyManager; -import android.text.TextUtils; -import android.util.Log; -import android.util.TypedValue; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.TextView; - -import androidx.appcompat.app.AlertDialog; -import androidx.core.net.ConnectivityManagerCompat; -import androidx.preference.PreferenceManager; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.InetAddress; -import java.net.InterfaceAddress; -import java.net.NetworkInterface; -import java.net.URL; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.text.DateFormat; -import java.text.NumberFormat; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class Util { - private static final String TAG = "NetGuard.Util"; - - // Roam like at home - private static final List listEU = Arrays.asList( - "AT", // Austria - "BE", // Belgium - "BG", // Bulgaria - "HR", // Croatia - "CY", // Cyprus - "CZ", // Czech Republic - "DK", // Denmark - "EE", // Estonia - "FI", // Finland - "FR", // France - "DE", // Germany - "GR", // Greece - "HU", // Hungary - "IS", // Iceland - "IE", // Ireland - "IT", // Italy - "LV", // Latvia - "LI", // Liechtenstein - "LT", // Lithuania - "LU", // Luxembourg - "MT", // Malta - "NL", // Netherlands - "NO", // Norway - "PL", // Poland - "PT", // Portugal - "RE", // La Réunion - "RO", // Romania - "SK", // Slovakia - "SI", // Slovenia - "ES", // Spain - "SE" // Sweden - ); - - private static native String jni_getprop(String name); - - private static native boolean is_numeric_address(String ip); - - private static native void dump_memory_profile(); - - static { - try { - System.loadLibrary("netguard"); - } catch (UnsatisfiedLinkError ignored) { - System.exit(1); - } - } - - public static String getSelfVersionName(Context context) { - try { - PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); - return pInfo.versionName; - } catch (PackageManager.NameNotFoundException ex) { - return ex.toString(); - } - } - - public static int getSelfVersionCode(Context context) { - try { - PackageInfo pInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); - return pInfo.versionCode; - } catch (PackageManager.NameNotFoundException ex) { - return -1; - } - } - - public static boolean isNetworkActive(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - return (cm != null && cm.getActiveNetworkInfo() != null); - } - - public static boolean isConnected(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - if (cm == null) - return false; - - NetworkInfo ni = cm.getActiveNetworkInfo(); - if (ni != null && ni.isConnected()) - return true; - - Network[] networks = cm.getAllNetworks(); - if (networks == null) - return false; - - for (Network network : networks) { - ni = cm.getNetworkInfo(network); - if (ni != null && ni.getType() != ConnectivityManager.TYPE_VPN && ni.isConnected()) - return true; - } - - return false; - } - - public static boolean isWifiActive(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo()); - return (ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI); - } - - public static boolean isMeteredNetwork(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - return (cm != null && ConnectivityManagerCompat.isActiveNetworkMetered(cm)); - } - - public static String getWifiSSID(Context context) { - WifiManager wm = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE); - String ssid = (wm == null ? null : wm.getConnectionInfo().getSSID()); - return (ssid == null ? "NULL" : ssid); - } - - public static int getNetworkType(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo()); - return (ni == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN : ni.getSubtype()); - } - - public static String getNetworkGeneration(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo ni = cm.getActiveNetworkInfo(); - return (ni != null && ni.getType() == ConnectivityManager.TYPE_MOBILE ? getNetworkGeneration(ni.getSubtype()) : null); - } - - public static boolean isRoaming(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo()); - return (ni != null && ni.isRoaming()); - } - - public static boolean isNational(Context context) { - try { - TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - return (tm != null && tm.getSimCountryIso() != null && tm.getSimCountryIso().equals(tm.getNetworkCountryIso())); - } catch (Throwable ignored) { - return false; - } - } - - public static boolean isEU(Context context) { - try { - TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - return (tm != null && isEU(tm.getSimCountryIso()) && isEU(tm.getNetworkCountryIso())); - } catch (Throwable ignored) { - return false; - } - } - - public static boolean isEU(String country) { - return (country != null && listEU.contains(country.toUpperCase())); - } - - public static boolean isPrivateDns(Context context) { - String dns_mode = Settings.Global.getString(context.getContentResolver(), "private_dns_mode"); - Log.i(TAG, "Private DNS mode=" + dns_mode); - if (dns_mode == null) - dns_mode = "off"; - return (!"off".equals(dns_mode)); - } - - public static String getPrivateDnsSpecifier(Context context) { - String dns_mode = Settings.Global.getString(context.getContentResolver(), "private_dns_mode"); - if ("hostname".equals(dns_mode)) - return Settings.Global.getString(context.getContentResolver(), "private_dns_specifier"); - else - return null; - } - - public static String getNetworkGeneration(int networkType) { - switch (networkType) { - case TelephonyManager.NETWORK_TYPE_1xRTT: - case TelephonyManager.NETWORK_TYPE_CDMA: - case TelephonyManager.NETWORK_TYPE_EDGE: - case TelephonyManager.NETWORK_TYPE_GPRS: - case TelephonyManager.NETWORK_TYPE_IDEN: - case TelephonyManager.NETWORK_TYPE_GSM: - return "2G"; - - case TelephonyManager.NETWORK_TYPE_EHRPD: - case TelephonyManager.NETWORK_TYPE_EVDO_0: - case TelephonyManager.NETWORK_TYPE_EVDO_A: - case TelephonyManager.NETWORK_TYPE_EVDO_B: - case TelephonyManager.NETWORK_TYPE_HSDPA: - case TelephonyManager.NETWORK_TYPE_HSPA: - case TelephonyManager.NETWORK_TYPE_HSPAP: - case TelephonyManager.NETWORK_TYPE_HSUPA: - case TelephonyManager.NETWORK_TYPE_UMTS: - case TelephonyManager.NETWORK_TYPE_TD_SCDMA: - return "3G"; - - case TelephonyManager.NETWORK_TYPE_LTE: - case TelephonyManager.NETWORK_TYPE_IWLAN: - return "4G"; - - default: - return "?G"; - } - } - - public static boolean hasPhoneStatePermission(Context context) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - return (context.checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED); - else - return true; - } - - public static List getDefaultDNS(Context context) { - List listDns = new ArrayList<>(); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - Network an = cm.getActiveNetwork(); - if (an != null) { - LinkProperties lp = cm.getLinkProperties(an); - if (lp != null) { - List dns = lp.getDnsServers(); - if (dns != null) - for (InetAddress d : dns) { - Log.i(TAG, "DNS from LP: " + d.getHostAddress()); - listDns.add(d.getHostAddress().split("%")[0]); - } - } - } - } else { - String dns1 = jni_getprop("net.dns1"); - String dns2 = jni_getprop("net.dns2"); - if (dns1 != null) - listDns.add(dns1.split("%")[0]); - if (dns2 != null) - listDns.add(dns2.split("%")[0]); - } - - return listDns; - } - - public static boolean isNumericAddress(String ip) { - return is_numeric_address(ip); - } - - public static boolean isInteractive(Context context) { - PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH) - return (pm != null && pm.isScreenOn()); - else - return (pm != null && pm.isInteractive()); - } - - public static boolean isPackageInstalled(String packageName, Context context) { - try { - context.getPackageManager().getPackageInfo(packageName, 0); - return true; - } catch (PackageManager.NameNotFoundException ignored) { - return false; - } - } - - public static boolean isSystem(int uid, Context context) { - PackageManager pm = context.getPackageManager(); - String[] pkgs = pm.getPackagesForUid(uid); - if (pkgs != null) - for (String pkg : pkgs) - if (isSystem(pkg, context)) - return true; - return false; - } - - public static boolean isSystem(String packageName, Context context) { - try { - PackageManager pm = context.getPackageManager(); - PackageInfo info = pm.getPackageInfo(packageName, 0); - return ((info.applicationInfo.flags & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0); - /* - PackageInfo pkg = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES); - PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES); - return (pkg != null && pkg.signatures != null && pkg.signatures.length > 0 && - sys.signatures.length > 0 && sys.signatures[0].equals(pkg.signatures[0])); - */ - } catch (PackageManager.NameNotFoundException ignore) { - return false; - } - } - - public static boolean hasInternet(String packageName, Context context) { - PackageManager pm = context.getPackageManager(); - return (pm.checkPermission("android.permission.INTERNET", packageName) == PackageManager.PERMISSION_GRANTED); - } - - public static boolean hasInternet(int uid, Context context) { - PackageManager pm = context.getPackageManager(); - String[] pkgs = pm.getPackagesForUid(uid); - if (pkgs != null) - for (String pkg : pkgs) - if (hasInternet(pkg, context)) - return true; - return false; - } - - public static boolean isEnabled(PackageInfo info, Context context) { - int setting; - try { - PackageManager pm = context.getPackageManager(); - setting = pm.getApplicationEnabledSetting(info.packageName); - } catch (IllegalArgumentException ex) { - setting = PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; - Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - if (setting == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) - return info.applicationInfo.enabled; - else - return (setting == PackageManager.COMPONENT_ENABLED_STATE_ENABLED); - } - - public static List getApplicationNames(int uid, Context context) { - List listResult = new ArrayList<>(); - if (uid == 0) - listResult.add(context.getString(R.string.title_root)); - else if (uid == 1013) - listResult.add(context.getString(R.string.title_mediaserver)); - else if (uid == 9999) - listResult.add(context.getString(R.string.title_nobody)); - else { - PackageManager pm = context.getPackageManager(); - String[] pkgs = pm.getPackagesForUid(uid); - if (pkgs == null) - listResult.add(Integer.toString(uid)); - else - for (String pkg : pkgs) - try { - ApplicationInfo info = pm.getApplicationInfo(pkg, 0); - listResult.add(pm.getApplicationLabel(info).toString()); - } catch (PackageManager.NameNotFoundException ignored) { - } - Collections.sort(listResult); - } - return listResult; - } - - public static boolean canFilter(Context context) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) - return true; - - // https://android-review.googlesource.com/#/c/206710/1/untrusted_app.te - File tcp = new File("/proc/net/tcp"); - File tcp6 = new File("/proc/net/tcp6"); - try { - if (tcp.exists() && tcp.canRead()) - return true; - } catch (SecurityException ignored) { - } - try { - return (tcp6.exists() && tcp6.canRead()); - } catch (SecurityException ignored) { - return false; - } - } - - public static boolean isDebuggable(Context context) { - return ((context.getApplicationContext().getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0); - } - - public static boolean isPlayStoreInstall(Context context) { - if (BuildConfig.PLAY_STORE_RELEASE) - return true; - try { - return "com.android.vending".equals(context.getPackageManager().getInstallerPackageName(context.getPackageName())); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - return false; - } - } - - public static boolean hasXposed(Context context) { - if (true || !isPlayStoreInstall(context)) - return false; - for (StackTraceElement ste : Thread.currentThread().getStackTrace()) - if (ste.getClassName().startsWith("de.robv.android.xposed")) - return true; - return false; - } - - public static boolean ownFault(Context context, Throwable ex) { - if (ex instanceof OutOfMemoryError) - return false; - if (ex.getCause() != null) - ex = ex.getCause(); - for (StackTraceElement ste : ex.getStackTrace()) - if (ste.getClassName().startsWith(context.getPackageName())) - return true; - return false; - } - - public static String getFingerprint(Context context) { - try { - PackageManager pm = context.getPackageManager(); - String pkg = context.getPackageName(); - PackageInfo info = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES); - byte[] cert = info.signatures[0].toByteArray(); - MessageDigest digest = MessageDigest.getInstance("SHA1"); - byte[] bytes = digest.digest(cert); - StringBuilder sb = new StringBuilder(); - for (byte b : bytes) - sb.append(Integer.toString(b & 0xff, 16).toLowerCase()); - return sb.toString(); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - return null; - } - } - - public static boolean hasValidFingerprint(Context context) { - String calculated = getFingerprint(context); - String expected = context.getString(R.string.fingerprint); - return (calculated != null && calculated.equals(expected)); - } - - public static void setTheme(Context context) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean dark = prefs.getBoolean("dark_theme", false); - String theme = prefs.getString("theme", "teal"); - if (theme.equals("teal")) - context.setTheme(dark ? R.style.AppThemeTealDark : R.style.AppThemeTeal); - else if (theme.equals("blue")) - context.setTheme(dark ? R.style.AppThemeBlueDark : R.style.AppThemeBlue); - else if (theme.equals("purple")) - context.setTheme(dark ? R.style.AppThemePurpleDark : R.style.AppThemePurple); - else if (theme.equals("amber")) - context.setTheme(dark ? R.style.AppThemeAmberDark : R.style.AppThemeAmber); - else if (theme.equals("orange")) - context.setTheme(dark ? R.style.AppThemeOrangeDark : R.style.AppThemeOrange); - else if (theme.equals("green")) - context.setTheme(dark ? R.style.AppThemeGreenDark : R.style.AppThemeGreen); - - if (context instanceof Activity && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) - setTaskColor(context); - } - - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - private static void setTaskColor(Context context) { - TypedValue tv = new TypedValue(); - context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); - ((Activity) context).setTaskDescription(new ActivityManager.TaskDescription(null, null, tv.data)); - } - - public static int dips2pixels(int dips, Context context) { - return Math.round(dips * context.getResources().getDisplayMetrics().density + 0.5f); - } - - private static int calculateInSampleSize( - BitmapFactory.Options options, int reqWidth, int reqHeight) { - int height = options.outHeight; - int width = options.outWidth; - int inSampleSize = 1; - - if (height > reqHeight || width > reqWidth) { - int halfHeight = height / 2; - int halfWidth = width / 2; - - while (halfHeight / inSampleSize >= reqHeight && halfWidth / inSampleSize >= reqWidth) - inSampleSize *= 2; - } - - return inSampleSize; - } - - public static Bitmap decodeSampledBitmapFromResource( - Resources resources, int resourceId, int reqWidth, int reqHeight) { - - BitmapFactory.Options options = new BitmapFactory.Options(); - options.inJustDecodeBounds = true; - BitmapFactory.decodeResource(resources, resourceId, options); - options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); - options.inJustDecodeBounds = false; - - return BitmapFactory.decodeResource(resources, resourceId, options); - } - - public static String getProtocolName(int protocol, int version, boolean brief) { - // https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers - String p = null; - String b = null; - switch (protocol) { - case 0: - p = "HOPO"; - b = "H"; - break; - case 2: - p = "IGMP"; - b = "G"; - break; - case 1: - case 58: - p = "ICMP"; - b = "I"; - break; - case 6: - p = "TCP"; - b = "T"; - break; - case 17: - p = "UDP"; - b = "U"; - break; - case 50: - p = "ESP"; - b = "E"; - break; - } - if (p == null) - return Integer.toString(protocol) + "/" + version; - return ((brief ? b : p) + (version > 0 ? version : "")); - } - - public interface DoubtListener { - void onSure(); - } - - public static void areYouSure(Context context, int explanation, final DoubtListener listener) { - LayoutInflater inflater = LayoutInflater.from(context); - View view = inflater.inflate(R.layout.sure, null, false); - TextView tvExplanation = view.findViewById(R.id.tvExplanation); - tvExplanation.setText(explanation); - new AlertDialog.Builder(context) - .setView(view) - .setCancelable(true) - .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - listener.onSure(); - } - }) - .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - // Do nothing - } - }) - .create().show(); - } - - private static final Map mapIPOrganization = new HashMap<>(); - - public static String getOrganization(String ip) throws Exception { - synchronized (mapIPOrganization) { - if (mapIPOrganization.containsKey(ip)) - return mapIPOrganization.get(ip); - } - BufferedReader reader = null; - try { - URL url = new URL("https://ipinfo.io/" + ip + "/org"); - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.setReadTimeout(15 * 1000); - connection.connect(); - reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String organization = reader.readLine(); - if ("undefined".equals(organization)) - organization = null; - synchronized (mapIPOrganization) { - mapIPOrganization.put(ip, organization); - } - return organization; - } finally { - if (reader != null) - reader.close(); - } - } - - public static String md5(String text, String salt) throws NoSuchAlgorithmException, UnsupportedEncodingException { - // MD5 - byte[] bytes = MessageDigest.getInstance("MD5").digest((text + salt).getBytes("UTF-8")); - StringBuilder sb = new StringBuilder(); - for (byte b : bytes) - sb.append(String.format("%02X", b)); - return sb.toString(); - } - - public static void logExtras(Intent intent) { - if (intent != null) - logBundle(intent.getExtras()); - } - - public static void logBundle(Bundle data) { - if (data != null) { - Set keys = data.keySet(); - StringBuilder stringBuilder = new StringBuilder(); - for (String key : keys) { - Object value = data.get(key); - stringBuilder.append(key) - .append("=") - .append(value) - .append(value == null ? "" : " (" + value.getClass().getSimpleName() + ")") - .append("\r\n"); - } - Log.d(TAG, stringBuilder.toString()); - } - } - - public static StringBuilder readString(InputStreamReader reader) { - StringBuilder sb = new StringBuilder(2048); - char[] read = new char[128]; - try { - for (int i; (i = reader.read(read)) >= 0; sb.append(read, 0, i)) ; - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - return sb; - } - - public static void sendCrashReport(Throwable ex, final Context context) { - if (!isPlayStoreInstall(context) || Util.isDebuggable(context)) - return; - - try { - ApplicationErrorReport report = new ApplicationErrorReport(); - report.packageName = report.processName = context.getPackageName(); - report.time = System.currentTimeMillis(); - report.type = ApplicationErrorReport.TYPE_CRASH; - report.systemApp = false; - - ApplicationErrorReport.CrashInfo crash = new ApplicationErrorReport.CrashInfo(); - crash.exceptionClassName = ex.getClass().getSimpleName(); - crash.exceptionMessage = ex.getMessage(); - - StringWriter writer = new StringWriter(); - PrintWriter printer = new PrintWriter(writer); - ex.printStackTrace(printer); - - crash.stackTrace = writer.toString(); - - StackTraceElement stack = ex.getStackTrace()[0]; - crash.throwClassName = stack.getClassName(); - crash.throwFileName = stack.getFileName(); - crash.throwLineNumber = stack.getLineNumber(); - crash.throwMethodName = stack.getMethodName(); - - report.crashInfo = crash; - - final Intent bug = new Intent(Intent.ACTION_APP_ERROR); - bug.putExtra(Intent.EXTRA_BUG_REPORT, report); - bug.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - if (bug.resolveActivity(context.getPackageManager()) != null) - context.startActivity(bug); - } catch (Throwable exex) { - Log.e(TAG, exex.toString() + "\n" + Log.getStackTraceString(exex)); - } - } - - public static String getGeneralInfo(Context context) { - StringBuilder sb = new StringBuilder(); - TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); - - sb.append(String.format("Interactive %B\r\n", isInteractive(context))); - sb.append(String.format("Connected %B\r\n", isConnected(context))); - sb.append(String.format("WiFi %B\r\n", isWifiActive(context))); - sb.append(String.format("Metered %B\r\n", isMeteredNetwork(context))); - sb.append(String.format("Roaming %B\r\n", isRoaming(context))); - - if (tm.getSimState() == TelephonyManager.SIM_STATE_READY) - sb.append(String.format("SIM %s/%s/%s\r\n", tm.getSimCountryIso(), tm.getSimOperatorName(), tm.getSimOperator())); - //if (tm.getNetworkType() != TelephonyManager.NETWORK_TYPE_UNKNOWN) - try { - sb.append(String.format("Network %s/%s/%s\r\n", tm.getNetworkCountryIso(), tm.getNetworkOperatorName(), tm.getNetworkOperator())); - } catch (Throwable ex) { - /* - 06-14 13:02:41.331 19703 19703 W ircode.netguar: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (greylist, reflection, allowed) - 06-14 13:02:41.332 19703 19703 W ircode.netguar: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (greylist, reflection, allowed) - 06-14 13:02:41.495 19703 19703 I TetheringManager: registerTetheringEventCallback:eu.faircode.netguard - 06-14 13:02:41.518 19703 19703 E AndroidRuntime: Process: eu.faircode.netguard, PID: 19703 - 06-14 13:02:41.518 19703 19703 E AndroidRuntime: at eu.faircode.netguard.Util.getGeneralInfo(SourceFile:744) - 06-14 13:02:41.518 19703 19703 E AndroidRuntime: at eu.faircode.netguard.ActivitySettings.updateTechnicalInfo(SourceFile:858) - 06-14 13:02:41.518 19703 19703 E AndroidRuntime: at eu.faircode.netguard.ActivitySettings.onPostCreate(SourceFile:425) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: java.lang.SecurityException: getDataNetworkTypeForSubscriber - 06-14 13:02:41.520 19703 19703 W NetGuard.App: java.lang.SecurityException: getDataNetworkTypeForSubscriber - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.os.Parcel.createExceptionOrNull(Parcel.java:2373) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.os.Parcel.createException(Parcel.java:2357) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.os.Parcel.readException(Parcel.java:2340) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.os.Parcel.readException(Parcel.java:2282) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at com.android.internal.telephony.ITelephony$Stub$Proxy.getNetworkTypeForSubscriber(ITelephony.java:8711) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2945) - 06-14 13:02:41.520 19703 19703 W NetGuard.App: at android.telephony.TelephonyManager.getNetworkType(TelephonyManager.java:2909) - */ - } - - PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) - sb.append(String.format("Power saving %B\r\n", pm.isPowerSaveMode())); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) - sb.append(String.format("Battery optimizing %B\r\n", batteryOptimizing(context))); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) - sb.append(String.format("Data saving %B\r\n", dataSaving(context))); - - if (sb.length() > 2) - sb.setLength(sb.length() - 2); - - return sb.toString(); - } - - public static String getNetworkInfo(Context context) { - StringBuilder sb = new StringBuilder(); - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - - NetworkInfo ani = cm.getActiveNetworkInfo(); - List listNI = new ArrayList<>(); - - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) - listNI.addAll(Arrays.asList(cm.getAllNetworkInfo())); - else - for (Network network : cm.getAllNetworks()) { - NetworkInfo ni = cm.getNetworkInfo(network); - if (ni != null) - listNI.add(ni); - } - - for (NetworkInfo ni : listNI) { - sb.append(ni.getTypeName()).append('/').append(ni.getSubtypeName()) - .append(' ').append(ni.getDetailedState()) - .append(TextUtils.isEmpty(ni.getExtraInfo()) ? "" : " " + ni.getExtraInfo()) - .append(ni.getType() == ConnectivityManager.TYPE_MOBILE ? " " + Util.getNetworkGeneration(ni.getSubtype()) : "") - .append(ni.isRoaming() ? " R" : "") - .append(ani != null && ni.getType() == ani.getType() && ni.getSubtype() == ani.getSubtype() ? " *" : "") - .append("\r\n"); - } - - try { - Enumeration nis = NetworkInterface.getNetworkInterfaces(); - if (nis != null) - while (nis.hasMoreElements()) { - NetworkInterface ni = nis.nextElement(); - if (ni != null && !ni.isLoopback()) { - List ias = ni.getInterfaceAddresses(); - if (ias != null) - for (InterfaceAddress ia : ias) - sb.append(ni.getName()) - .append(' ').append(ia.getAddress().getHostAddress()) - .append('/').append(ia.getNetworkPrefixLength()) - .append(' ').append(ni.getMTU()) - .append(' ').append(ni.isUp() ? '^' : 'v') - .append("\r\n"); - } - } - } catch (Throwable ex) { - sb.append(ex.toString()).append("\r\n"); - } - - if (sb.length() > 2) - sb.setLength(sb.length() - 2); - - return sb.toString(); - } - - @TargetApi(Build.VERSION_CODES.M) - public static boolean batteryOptimizing(Context context) { - PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); - return !pm.isIgnoringBatteryOptimizations(context.getPackageName()); - } - - @TargetApi(Build.VERSION_CODES.N) - public static boolean dataSaving(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - return (cm.getRestrictBackgroundStatus() == ConnectivityManager.RESTRICT_BACKGROUND_STATUS_ENABLED); - } - - public static void sendLogcat(final Uri uri, final Context context) { - AsyncTask task = new AsyncTask() { - @Override - protected Intent doInBackground(Object... objects) { - StringBuilder sb = new StringBuilder(); - sb.append(context.getString(R.string.msg_issue)); - sb.append("\r\n\r\n\r\n\r\n"); - - // Get version info - String version = getSelfVersionName(context); - sb.append(String.format("NetGuard: %s/%d\r\n", version, getSelfVersionCode(context))); - sb.append(String.format("Android: %s (SDK %d)\r\n", Build.VERSION.RELEASE, Build.VERSION.SDK_INT)); - sb.append("\r\n"); - - // Get device info - sb.append(String.format("Brand: %s\r\n", Build.BRAND)); - sb.append(String.format("Manufacturer: %s\r\n", Build.MANUFACTURER)); - sb.append(String.format("Model: %s\r\n", Build.MODEL)); - sb.append(String.format("Product: %s\r\n", Build.PRODUCT)); - sb.append(String.format("Device: %s\r\n", Build.DEVICE)); - sb.append(String.format("Host: %s\r\n", Build.HOST)); - sb.append(String.format("Display: %s\r\n", Build.DISPLAY)); - sb.append(String.format("Id: %s\r\n", Build.ID)); - sb.append(String.format("Fingerprint: %B\r\n", hasValidFingerprint(context))); - - String abi; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) - abi = Build.CPU_ABI; - else - abi = (Build.SUPPORTED_ABIS.length > 0 ? Build.SUPPORTED_ABIS[0] : "?"); - sb.append(String.format("ABI: %s\r\n", abi)); - - Runtime rt = Runtime.getRuntime(); - long hused = (rt.totalMemory() - rt.freeMemory()) / 1024L; - long hmax = rt.maxMemory() / 1024L; - long nheap = Debug.getNativeHeapAllocatedSize() / 1024L; - NumberFormat nf = NumberFormat.getIntegerInstance(); - sb.append(String.format("Heap usage: %s/%s KiB native: %s KiB\r\n", - nf.format(hused), nf.format(hmax), nf.format(nheap))); - - sb.append("\r\n"); - - sb.append(String.format("VPN dialogs: %B\r\n", isPackageInstalled("com.android.vpndialogs", context))); - try { - sb.append(String.format("Prepared: %B\r\n", VpnService.prepare(context) == null)); - } catch (Throwable ex) { - sb.append("Prepared: ").append((ex.toString())).append("\r\n").append(Log.getStackTraceString(ex)); - } - sb.append("\r\n"); - - sb.append(getGeneralInfo(context)); - sb.append("\r\n\r\n"); - sb.append(getNetworkInfo(context)); - sb.append("\r\n\r\n"); - - // Get DNS - sb.append("DNS system:\r\n"); - for (String dns : getDefaultDNS(context)) - sb.append("- ").append(dns).append("\r\n"); - sb.append("DNS VPN:\r\n"); - for (InetAddress dns : ServiceSinkhole.getDns(context)) - sb.append("- ").append(dns).append("\r\n"); - sb.append("\r\n"); - - // Get TCP connection info - String line; - BufferedReader in; - try { - sb.append("/proc/net/tcp:\r\n"); - in = new BufferedReader(new FileReader("/proc/net/tcp")); - while ((line = in.readLine()) != null) - sb.append(line).append("\r\n"); - in.close(); - sb.append("\r\n"); - - sb.append("/proc/net/tcp6:\r\n"); - in = new BufferedReader(new FileReader("/proc/net/tcp6")); - while ((line = in.readLine()) != null) - sb.append(line).append("\r\n"); - in.close(); - sb.append("\r\n"); - - } catch (IOException ex) { - sb.append(ex.toString()).append("\r\n"); - } - - // Get settings - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - Map all = prefs.getAll(); - for (String key : all.keySet()) - sb.append("Setting: ").append(key).append('=').append(all.get(key)).append("\r\n"); - sb.append("\r\n"); - - // Write logcat - dump_memory_profile(); - OutputStream out = null; - try { - Log.i(TAG, "Writing logcat URI=" + uri); - out = context.getContentResolver().openOutputStream(uri); - out.write(getLogcat().toString().getBytes()); - out.write(getTrafficLog(context).toString().getBytes()); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - sb.append(ex.toString()).append("\r\n").append(Log.getStackTraceString(ex)).append("\r\n"); - } finally { - if (out != null) - try { - out.close(); - } catch (IOException ignored) { - } - } - - // Build intent - Intent sendEmail = new Intent(Intent.ACTION_SEND); - sendEmail.setType("message/rfc822"); - sendEmail.putExtra(Intent.EXTRA_EMAIL, new String[]{"marcel+netguard@faircode.eu"}); - sendEmail.putExtra(Intent.EXTRA_SUBJECT, "NetGuard " + version + " logcat"); - sendEmail.putExtra(Intent.EXTRA_TEXT, sb.toString()); - sendEmail.putExtra(Intent.EXTRA_STREAM, uri); - return sendEmail; - } - - @Override - protected void onPostExecute(Intent sendEmail) { - if (sendEmail != null) - try { - context.startActivity(sendEmail); - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - }; - task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - - private static StringBuilder getTrafficLog(Context context) { - StringBuilder sb = new StringBuilder(); - - try (Cursor cursor = DatabaseHelper.getInstance(context).getLog(true, true, true, true, true)) { - - int colTime = cursor.getColumnIndex("time"); - int colVersion = cursor.getColumnIndex("version"); - int colProtocol = cursor.getColumnIndex("protocol"); - int colFlags = cursor.getColumnIndex("flags"); - int colSAddr = cursor.getColumnIndex("saddr"); - int colSPort = cursor.getColumnIndex("sport"); - int colDAddr = cursor.getColumnIndex("daddr"); - int colDPort = cursor.getColumnIndex("dport"); - int colDName = cursor.getColumnIndex("dname"); - int colUid = cursor.getColumnIndex("uid"); - int colData = cursor.getColumnIndex("data"); - int colAllowed = cursor.getColumnIndex("allowed"); - int colConnection = cursor.getColumnIndex("connection"); - int colInteractive = cursor.getColumnIndex("interactive"); - - DateFormat format = SimpleDateFormat.getDateTimeInstance(); - - int count = 0; - while (cursor.moveToNext() && ++count < 250) { - sb.append(format.format(cursor.getLong(colTime))); - sb.append(" v").append(cursor.getInt(colVersion)); - sb.append(" p").append(cursor.getInt(colProtocol)); - sb.append(' ').append(cursor.getString(colFlags)); - sb.append(' ').append(cursor.getString(colSAddr)); - sb.append('/').append(cursor.getInt(colSPort)); - sb.append(" > ").append(cursor.getString(colDAddr)); - sb.append('/').append(cursor.getString(colDName)); - sb.append('/').append(cursor.getInt(colDPort)); - sb.append(" u").append(cursor.getInt(colUid)); - sb.append(" a").append(cursor.getInt(colAllowed)); - sb.append(" c").append(cursor.getInt(colConnection)); - sb.append(" i").append(cursor.getInt(colInteractive)); - sb.append(' ').append(cursor.getString(colData)); - sb.append("\r\n"); - } - } - - return sb; - } - - private static StringBuilder getLogcat() { - StringBuilder builder = new StringBuilder(); - Process process1 = null; - Process process2 = null; - BufferedReader br = null; - try { - String[] command1 = new String[]{"logcat", "-d", "-v", "threadtime"}; - process1 = Runtime.getRuntime().exec(command1); - br = new BufferedReader(new InputStreamReader(process1.getInputStream())); - int count = 0; - String line; - while ((line = br.readLine()) != null) { - count++; - builder.append(line).append("\r\n"); - } - Log.i(TAG, "Logcat lines=" + count); - - } catch (IOException ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } finally { - if (br != null) - try { - br.close(); - } catch (IOException ignored) { - } - if (process2 != null) - try { - process2.destroy(); - } catch (Throwable ex) { - Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - if (process1 != null) - try { - process1.destroy(); - } catch (Throwable ex) { - Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - return builder; - } -} diff --git a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/WidgetMain.java b/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/WidgetMain.java deleted file mode 100644 index 9e557fd..0000000 --- a/NetworkGenie/app/src/main/main/java/eu/faircode/netguard/WidgetMain.java +++ /dev/null @@ -1,70 +0,0 @@ -package eu.faircode.netguard; - -/* - 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 . - - Copyright 2015-2019 by Marcel Bokhorst (M66B) -*/ - -import android.app.PendingIntent; -import android.appwidget.AppWidgetManager; -import android.appwidget.AppWidgetProvider; -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.util.Log; -import android.widget.RemoteViews; - -import androidx.preference.PreferenceManager; - -public class WidgetMain extends AppWidgetProvider { - private static final String TAG = "NetGuard.Widget"; - - @Override - public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { - update(appWidgetIds, appWidgetManager, context); - } - - private static void update(int[] appWidgetIds, AppWidgetManager appWidgetManager, Context context) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean enabled = prefs.getBoolean("enabled", false); - - try { - try { - Intent intent = new Intent(enabled ? WidgetAdmin.INTENT_OFF : WidgetAdmin.INTENT_ON); - intent.setPackage(context.getPackageName()); - PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE); - for (int id : appWidgetIds) { - RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widgetmain); - views.setOnClickPendingIntent(R.id.ivEnabled, pi); - views.setImageViewResource(R.id.ivEnabled, enabled ? R.drawable.ic_security_color_24dp : R.drawable.ic_security_white_24dp_60); - appWidgetManager.updateAppWidget(id, views); - } - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } catch (Throwable ex) { - Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); - } - } - - public static void updateWidgets(Context context) { - AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); - int appWidgetIds[] = AppWidgetManager.getInstance(context).getAppWidgetIds(new ComponentName(context, WidgetMain.class)); - update(appWidgetIds, appWidgetManager, context); - } -} diff --git a/NetworkGenie/app/src/main/main/jni/netguard/debug_conn.c b/NetworkGenie/app/src/main/main/jni/netguard/debug_conn.c deleted file mode 100644 index 759c478..0000000 --- a/NetworkGenie/app/src/main/main/jni/netguard/debug_conn.c +++ /dev/null @@ -1,372 +0,0 @@ -// -// Created by conntrack on 4/30/23. -// - - -#include "netguard.h" - -struct ng_session *debug_socket; - - -const char* debug_src_ip=""; // Android wlan IP -const char* debug_dest_ip=""; // Debug server pub IP - -const uint16_t sport = 40408; // local port -const uint16_t dport = 50508; // server port - - - -// pseudo header needed for tcp header checksum calculation -struct pseudo_header -{ - u_int32_t source_address; - u_int32_t dest_address; - u_int8_t placeholder; - u_int8_t protocol; - u_int16_t tcp_length; -}; - -#define DATAGRAM_LEN 4096 -#define OPT_SIZE 20 - -unsigned short checksum(const char *buf, unsigned size) -{ - unsigned sum = 0, i; - - /* Accumulate checksum */ - for (i = 0; i < size - 1; i += 2) - { - unsigned short word16 = *(unsigned short *) &buf[i]; - sum += word16; - } - - /* Handle odd-sized case */ - if (size & 1) - { - unsigned short word16 = (unsigned char) buf[i]; - sum += word16; - } - - /* Fold to get the ones-complement result */ - while (sum >> 16) sum = (sum & 0xFFFF)+(sum >> 16); - - /* Invert to get the negative in ones-complement arithmetic */ - return ~sum; -} - - -void create_data_packet(char** out_packet, int* out_packet_len, struct tcp_session tcps) -{ - // datagram to represent the packet - char *datagram = calloc(DATAGRAM_LEN, sizeof(char)); - - // required structs for IP and TCP header - struct iphdr *iph = (struct iphdr*)datagram; - struct tcphdr *tcph = (struct tcphdr*)(datagram + sizeof(struct iphdr)); - struct pseudo_header psh; - - char source_ip[32]; - struct sockaddr_in sin; - - //some address resolution - strcpy(source_ip , debug_src_ip); // cli ip - sin.sin_family = AF_INET; - sin.sin_port = htons(dport); // server port - sin.sin_addr.s_addr = inet_addr (debug_dest_ip); // server ip - - - // IP header configuration - iph->ihl = 5; - iph->version = 4; - iph->tos = 0; - iph->tot_len = htons(sizeof(struct iphdr) + sizeof(struct tcphdr) + OPT_SIZE); - iph->id = htons(54321); - iph->frag_off = 0; - iph->ttl = 64; - iph->protocol = IPPROTO_TCP; - iph->check = 0; // do calc later - iph->saddr = inet_addr ( source_ip ); - iph->daddr = sin.sin_addr.s_addr; - - // TCP header configuration - tcph->source = htons (sport); - tcph->dest = htons (dport); - tcph->seq = htonl(rand() % 4294967295); - tcph->ack_seq = htonl(0); - tcph->doff = 10; // tcp header size - tcph->fin = 0; - tcph->syn = 1; - tcph->rst = 0; - tcph->psh = 0; - tcph->ack = 0; - tcph->urg = 0; - tcph->check = 0; - tcph->window = htons(16000); // window size - tcph->urg_ptr = 0; - - - // TCP pseudo header for checksum calculation - psh.source_address = inet_addr ( source_ip ); - psh.dest_address = sin.sin_addr.s_addr; - psh.placeholder = 0; - psh.protocol = IPPROTO_TCP; - psh.tcp_length = htons(sizeof(struct tcphdr) + OPT_SIZE); - int psize = sizeof(struct pseudo_header) + sizeof(struct tcphdr) + OPT_SIZE; - // fill pseudo packet - char* pseudogram = malloc(psize); - memcpy(pseudogram, (char*)&psh, sizeof(struct pseudo_header)); - memcpy(pseudogram + sizeof(struct pseudo_header), tcph, sizeof(struct tcphdr) + OPT_SIZE); - - // TODO: change options to PA - // TCP options are only set in the SYN packet - // ---- set mss ---- - datagram[40] = 0x02; - datagram[41] = 0x04; - int16_t mss = htons(48); // mss value - memcpy(datagram + 42, &mss, sizeof(int16_t)); - // ---- enable SACK ---- - datagram[44] = 0x04; - datagram[45] = 0x02; - // do the same for the pseudo header - pseudogram[32] = 0x02; - pseudogram[33] = 0x04; - memcpy(pseudogram + 34, &mss, sizeof(int16_t)); - pseudogram[36] = 0x04; - pseudogram[37] = 0x02; - - tcph->check = checksum((const char*)pseudogram, psize); - iph->check = checksum((const char*)datagram, iph->tot_len); - - *out_packet = datagram; - *out_packet_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + OPT_SIZE; - free(pseudogram); - - - - - -} - -void create_syn_packet(char** out_packet, int* out_packet_len) -{ - // datagram to represent the packet - char *datagram = calloc(DATAGRAM_LEN, sizeof(char)); - - // required structs for IP and TCP header - struct iphdr *iph = (struct iphdr*)datagram; - struct tcphdr *tcph = (struct tcphdr*)(datagram + sizeof(struct iphdr)); - struct pseudo_header psh; - - char source_ip[32]; - struct sockaddr_in sin; - - //some address resolution - strcpy(source_ip , debug_src_ip); // cli ip - sin.sin_family = AF_INET; - sin.sin_port = htons(dport); // server port - sin.sin_addr.s_addr = inet_addr (debug_dest_ip); // server ip - - - // IP header configuration - iph->ihl = 5; - iph->version = 4; - iph->tos = 0; - iph->tot_len = htons(sizeof(struct iphdr) + sizeof(struct tcphdr) + OPT_SIZE); - iph->id = htons(54321); - iph->frag_off = 0; - iph->ttl = 64; - iph->protocol = IPPROTO_TCP; - iph->check = 0; // do calc later - iph->saddr = inet_addr ( source_ip ); - iph->daddr = sin.sin_addr.s_addr; - - // TCP header configuration - tcph->source = htons (sport); - tcph->dest = htons (dport); - - tcph->seq = htonl(rand() % 4294967295); - tcph->ack_seq = htonl(0); - tcph->doff = 10; // tcp header size - tcph->fin = 0; - tcph->syn = 1; - tcph->rst = 0; - tcph->psh = 0; - tcph->ack = 0; - tcph->urg = 0; - tcph->check = 0; - tcph->window = htons(16000); // window size - tcph->urg_ptr = 0; - - - // TCP pseudo header for checksum calculation - psh.source_address = inet_addr ( source_ip ); - psh.dest_address = sin.sin_addr.s_addr; - psh.placeholder = 0; - psh.protocol = IPPROTO_TCP; - psh.tcp_length = htons(sizeof(struct tcphdr) + OPT_SIZE); - int psize = sizeof(struct pseudo_header) + sizeof(struct tcphdr) + OPT_SIZE; - // fill pseudo packet - char* pseudogram = malloc(psize); - memcpy(pseudogram, (char*)&psh, sizeof(struct pseudo_header)); - memcpy(pseudogram + sizeof(struct pseudo_header), tcph, sizeof(struct tcphdr) + OPT_SIZE); - - // TCP options are only set in the SYN packet - // ---- set mss ---- - datagram[40] = 0x02; - datagram[41] = 0x04; - int16_t mss = htons(48); // mss value - memcpy(datagram + 42, &mss, sizeof(int16_t)); - // ---- enable SACK ---- - datagram[44] = 0x04; - datagram[45] = 0x02; - // do the same for the pseudo header - pseudogram[32] = 0x02; - pseudogram[33] = 0x04; - memcpy(pseudogram + 34, &mss, sizeof(int16_t)); - pseudogram[36] = 0x04; - pseudogram[37] = 0x02; - - tcph->check = checksum((const char*)pseudogram, psize); - iph->check = checksum((const char*)datagram, iph->tot_len); - - *out_packet = datagram; - *out_packet_len = sizeof(struct iphdr) + sizeof(struct tcphdr) + OPT_SIZE; - free(pseudogram); - -} - - - -int write_data_packet(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length) { - // send PSH data - char* psh_packet; - int psh_packet_len; - - psh_packet = "testoooo"; - psh_packet_len = 8; - - //create_data_packet(&psh_packet, &psh_packet_len, tcps); - //handle_ip(args, psh_packet, (size_t) psh_packet_len, epoll_fd, 10, 200); - - //write(debug_socket->socket, psh_packet, (size_t) psh_packet_len); - write(debug_socket->socket, buffer, length); - - //write_ack(args, &debug_socket->tcp); this will send acks from dst to source (wrong direction) if uncommented - log_android(ANDROID_LOG_ERROR, "Handling push data IP create with length: %d", psh_packet_len); - -} - - - - -int open_debug_packet(const struct arguments *args, int epoll_fd) { - - // send SYN - char* packet; - int packet_len; - - create_syn_packet(&packet, &packet_len); - - handle_ip(args, packet, (size_t) packet_len, epoll_fd, 10, 200); - - - /* - ssize_t res = write(args->tun, packet, (size_t) packet_len); - - if (res >= 0) { - log_android(ANDROID_LOG_ERROR, "successfuly wrote new syn packet to tun"); - //handle_ip(args, packet, (size_t) packet_len, epoll_fd, 10, 200); - } else { - log_android(ANDROID_LOG_ERROR, "tcp write error.."); - } - */ - - - return 1; -} - - - - -int debug_socket_init(const struct arguments *args, int epoll_fd) { - - log_android(ANDROID_LOG_ERROR, "init debug socket"); - open_debug_packet(args, epoll_fd); - - return 1; - -} - - -struct ng_session *get_debug_session(const struct arguments *args) { - - - // Search session - struct ng_session *cur = args->ctx->ng_session; - while (cur != NULL && - !(cur->protocol == IPPROTO_TCP && - cur->tcp.version == 4 && - cur->tcp.source == ntohs(40408) && cur->tcp.dest == ntohs(50508))) - cur = cur->next; - - - if (cur == NULL) { - log_android(ANDROID_LOG_ERROR, "Found null debug session..."); - } else { - log_android(ANDROID_LOG_ERROR, "Found the debug session.."); - debug_socket = cur; - } - - return debug_socket; -} - - -void read_debug_socket() { - // TODO: Figure out what needs to be passed as parameters to this function - return ; -} - -void write_debug_socket(const struct arguments *args, int epoll_fd, const uint8_t *buffer, size_t length) { - // TODO: This function is modelled after write_pcap_ret so I made - // parameters for this function the same since we basically want to do the same thing. - - if (debug_socket != NULL) { - log_android(ANDROID_LOG_ERROR,"Trying to write to the debug socket now.."); - write_data_packet(args, epoll_fd, buffer, length); - } - - - /* - struct tcp_session *cur = &debug_socket->tcp; - - - // test write to the debug socket - //write_data(args, cur, buffer, length); - - log_android(ANDROID_LOG_ERROR, "debug tcp port: %d", cur->source); - - int is_debug_server = strcmp(dest_ip, ""); - if (is_debug_server != 0) { - - int res = write_ack(args, &debug_socket->tcp); - log_android(ANDROID_LOG_ERROR, "write ack result %d", res); - log_android(ANDROID_LOG_ERROR, "writing debug packet to %s with length: %d", dest_ip, length); - - // Forward to tun - if (write_data(args, &debug_socket->tcp, buffer, length) >= 0) { - log_android(ANDROID_LOG_ERROR, "Successfully wrote to debug socket with length: %d", length); - debug_socket->tcp.local_seq += length; - debug_socket->tcp.unconfirmed++; - } - } else { - log_android(ANDROID_LOG_ERROR, "skipping writing debug packet to %s with length: %d", dest_ip, length); - } - - */ - - -} - - - - diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_add_circle_outline_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_add_circle_outline_white_24dp.png deleted file mode 100644 index 67e53a6..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_add_circle_outline_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_attach_money_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_attach_money_black_24dp.png deleted file mode 100644 index ad0f76c..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_attach_money_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_attach_money_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_attach_money_white_24dp.png deleted file mode 100644 index ee833c6..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_attach_money_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_check_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_check_white_24dp.png deleted file mode 100644 index 729f290..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_check_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_close_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_close_white_24dp.png deleted file mode 100644 index ceb1a1e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_close_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_cloud_upload_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_cloud_upload_white_24dp.png deleted file mode 100644 index 5e0b464..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_cloud_upload_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_delete_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_delete_black_24dp.png deleted file mode 100644 index dbbb602..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_delete_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_delete_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_delete_white_24dp.png deleted file mode 100644 index 4a9f769..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_delete_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_equalizer_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_equalizer_white_24dp.png deleted file mode 100644 index aa343b5..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_equalizer_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_equalizer_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_equalizer_white_24dp_60.png deleted file mode 100644 index 933a198..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_equalizer_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_error_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_error_white_24dp.png deleted file mode 100644 index 69cbb1e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_error_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_less_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_less_black_24dp.png deleted file mode 100644 index 57139a7..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_less_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_less_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_less_white_24dp.png deleted file mode 100644 index dea8988..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_less_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_more_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_more_black_24dp.png deleted file mode 100644 index 9625f14..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_more_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_more_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_more_white_24dp.png deleted file mode 100644 index 022e057..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_expand_more_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_file_download_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_file_download_white_24dp.png deleted file mode 100644 index c8a2039..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_file_download_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_filter_list_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_filter_list_white_24dp.png deleted file mode 100644 index 7e8a6b5..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_filter_list_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_filter_list_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_filter_list_white_24dp_60.png deleted file mode 100644 index 8c2d618..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_filter_list_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_hourglass_empty_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_hourglass_empty_black_24dp.png deleted file mode 100644 index 22fe56d..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_hourglass_empty_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_hourglass_empty_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_hourglass_empty_white_24dp.png deleted file mode 100644 index 5b8b684..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_hourglass_empty_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_launch_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_launch_black_24dp.png deleted file mode 100644 index 4cfcf84..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_launch_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_launch_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_launch_white_24dp.png deleted file mode 100644 index 49726bc..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_launch_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_lock_open_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_lock_open_white_24dp.png deleted file mode 100644 index 6bae68f..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_lock_open_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_lock_outline_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_lock_outline_white_24dp.png deleted file mode 100644 index e53f541..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_lock_outline_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_lock_outline_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_lock_outline_white_24dp_60.png deleted file mode 100644 index 0e8a7cf..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_lock_outline_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_pause_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_pause_black_24dp.png deleted file mode 100644 index 3539b4e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_pause_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_pause_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_pause_white_24dp.png deleted file mode 100644 index 4d2ea05..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_pause_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_perm_data_setting_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_perm_data_setting_black_24dp.png deleted file mode 100644 index 1643436..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_perm_data_setting_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_perm_data_setting_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_perm_data_setting_white_24dp.png deleted file mode 100644 index ba7e1fe..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_perm_data_setting_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_perm_identity_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_perm_identity_white_24dp.png deleted file mode 100644 index 78d43f0..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_perm_identity_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_play_arrow_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_play_arrow_black_24dp.png deleted file mode 100644 index e9c288c..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_play_arrow_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_play_arrow_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_play_arrow_white_24dp.png deleted file mode 100644 index 57c9fa5..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_play_arrow_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_search_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_search_white_24dp.png deleted file mode 100644 index bbfbc96..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_search_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_security_color_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_security_color_24dp.png deleted file mode 100644 index 73e31c1..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_security_color_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_security_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_security_white_24dp.png deleted file mode 100644 index 262800a..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_security_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_security_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_security_white_24dp_60.png deleted file mode 100644 index d559fee..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_security_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_settings_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_settings_black_24dp.png deleted file mode 100644 index acf1ddf..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_settings_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_settings_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_settings_white_24dp.png deleted file mode 100644 index 97ded33..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_settings_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_shopping_cart_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_shopping_cart_black_24dp.png deleted file mode 100644 index c2422ce..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_shopping_cart_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_shopping_cart_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_shopping_cart_white_24dp.png deleted file mode 100644 index a68ce43..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_shopping_cart_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_cellular_4_bar_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_cellular_4_bar_white_24dp.png deleted file mode 100644 index 1765e94..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_cellular_4_bar_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_cellular_off_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_cellular_off_white_24dp.png deleted file mode 100644 index 12704b3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_cellular_off_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_wifi_4_bar_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_wifi_4_bar_white_24dp.png deleted file mode 100644 index 5a53192..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_wifi_4_bar_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_wifi_off_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_wifi_off_white_24dp.png deleted file mode 100644 index 996d8a3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_signal_wifi_off_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_sort_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_sort_white_24dp.png deleted file mode 100644 index 55a429b..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-hdpi/ic_sort_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_add_circle_outline_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_add_circle_outline_white_24dp.png deleted file mode 100644 index 803fc97..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_add_circle_outline_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_attach_money_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_attach_money_black_24dp.png deleted file mode 100644 index 2ae5e6d..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_attach_money_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_attach_money_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_attach_money_white_24dp.png deleted file mode 100644 index 707d167..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_attach_money_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_check_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_check_white_24dp.png deleted file mode 100644 index dfcb55d..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_check_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_close_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_close_white_24dp.png deleted file mode 100644 index af7f828..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_close_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_cloud_upload_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_cloud_upload_white_24dp.png deleted file mode 100644 index aa64062..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_cloud_upload_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_delete_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_delete_black_24dp.png deleted file mode 100644 index 999aa4c..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_delete_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_delete_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_delete_white_24dp.png deleted file mode 100644 index e2f5f35..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_delete_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_equalizer_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_equalizer_white_24dp.png deleted file mode 100644 index bc600d3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_equalizer_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_equalizer_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_equalizer_white_24dp_60.png deleted file mode 100644 index 90ef1df..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_equalizer_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_error_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_error_white_24dp.png deleted file mode 100644 index ca148fc..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_error_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_less_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_less_black_24dp.png deleted file mode 100644 index 08c16a3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_less_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_less_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_less_white_24dp.png deleted file mode 100644 index a2e4baa..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_less_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_more_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_more_black_24dp.png deleted file mode 100644 index feb85a7..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_more_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_more_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_more_white_24dp.png deleted file mode 100644 index 910bb2a..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_expand_more_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_file_download_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_file_download_white_24dp.png deleted file mode 100644 index d400472..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_file_download_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_filter_list_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_filter_list_white_24dp.png deleted file mode 100644 index 59a2ec7..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_filter_list_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_filter_list_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_filter_list_white_24dp_60.png deleted file mode 100644 index 7b75cca..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_filter_list_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_hourglass_empty_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_hourglass_empty_black_24dp.png deleted file mode 100644 index ce8b8b0..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_hourglass_empty_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_hourglass_empty_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_hourglass_empty_white_24dp.png deleted file mode 100644 index 616df09..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_hourglass_empty_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_launch_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_launch_black_24dp.png deleted file mode 100644 index cc2892d..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_launch_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_launch_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_launch_white_24dp.png deleted file mode 100644 index 474cc80..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_launch_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_lock_open_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_lock_open_white_24dp.png deleted file mode 100644 index 3f47b54..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_lock_open_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_lock_outline_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_lock_outline_white_24dp.png deleted file mode 100644 index 13f432f..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_lock_outline_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_lock_outline_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_lock_outline_white_24dp_60.png deleted file mode 100644 index 19c3962..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_lock_outline_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_pause_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_pause_black_24dp.png deleted file mode 100644 index 6145664..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_pause_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_pause_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_pause_white_24dp.png deleted file mode 100644 index 2272d47..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_pause_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_perm_data_setting_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_perm_data_setting_black_24dp.png deleted file mode 100644 index 6686406..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_perm_data_setting_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_perm_data_setting_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_perm_data_setting_white_24dp.png deleted file mode 100644 index b2249e0..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_perm_data_setting_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_perm_identity_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_perm_identity_white_24dp.png deleted file mode 100644 index f00e3f3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_perm_identity_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_play_arrow_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_play_arrow_black_24dp.png deleted file mode 100644 index d78c57b..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_play_arrow_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_play_arrow_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_play_arrow_white_24dp.png deleted file mode 100644 index c61e948..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_play_arrow_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_search_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_search_white_24dp.png deleted file mode 100644 index faefc59..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_search_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_security_color_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_security_color_24dp.png deleted file mode 100644 index d023f2f..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_security_color_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_security_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_security_white_24dp.png deleted file mode 100644 index 44ee734..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_security_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_security_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_security_white_24dp_60.png deleted file mode 100644 index 93e76da..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_security_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_settings_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_settings_black_24dp.png deleted file mode 100644 index c59419c..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_settings_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_settings_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_settings_white_24dp.png deleted file mode 100644 index 8909c35..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_settings_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_shopping_cart_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_shopping_cart_black_24dp.png deleted file mode 100644 index f56585b..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_shopping_cart_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_shopping_cart_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_shopping_cart_white_24dp.png deleted file mode 100644 index 9d9fdbb..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_shopping_cart_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_cellular_4_bar_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_cellular_4_bar_white_24dp.png deleted file mode 100644 index 8d76fd4..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_cellular_4_bar_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_cellular_off_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_cellular_off_white_24dp.png deleted file mode 100644 index eaaa180..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_cellular_off_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_wifi_4_bar_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_wifi_4_bar_white_24dp.png deleted file mode 100644 index dd5a42f..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_wifi_4_bar_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_wifi_off_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_wifi_off_white_24dp.png deleted file mode 100644 index 5295ecd..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_signal_wifi_off_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_sort_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_sort_white_24dp.png deleted file mode 100644 index 3d84a44..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-mdpi/ic_sort_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_add_circle_outline_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_add_circle_outline_white_24dp.png deleted file mode 100644 index ac94274..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_add_circle_outline_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_attach_money_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_attach_money_black_24dp.png deleted file mode 100644 index c94dc6a..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_attach_money_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_attach_money_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_attach_money_white_24dp.png deleted file mode 100644 index 20efc6c..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_attach_money_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_check_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_check_white_24dp.png deleted file mode 100644 index 3b2b65d..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_check_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_close_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_close_white_24dp.png deleted file mode 100644 index b7c7ffd..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_close_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_cloud_upload_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_cloud_upload_white_24dp.png deleted file mode 100644 index a9602d1..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_cloud_upload_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_delete_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_delete_black_24dp.png deleted file mode 100644 index 796ccd2..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_delete_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_delete_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_delete_white_24dp.png deleted file mode 100644 index 388b5b0..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_delete_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_equalizer_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_equalizer_white_24dp.png deleted file mode 100644 index 40c572c..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_equalizer_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_equalizer_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_equalizer_white_24dp_60.png deleted file mode 100644 index 1d849fc..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_equalizer_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_error_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_error_white_24dp.png deleted file mode 100644 index 9829698..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_error_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_less_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_less_black_24dp.png deleted file mode 100644 index 323360e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_less_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_less_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_less_white_24dp.png deleted file mode 100644 index ae36d91..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_less_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_more_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_more_black_24dp.png deleted file mode 100644 index d3ee65e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_more_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_more_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_more_white_24dp.png deleted file mode 100644 index c42e2a0..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_expand_more_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_file_download_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_file_download_white_24dp.png deleted file mode 100644 index f53cc0c..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_file_download_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_filter_list_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_filter_list_white_24dp.png deleted file mode 100644 index 9416c70..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_filter_list_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_filter_list_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_filter_list_white_24dp_60.png deleted file mode 100644 index f8c9122..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_filter_list_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_hourglass_empty_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_hourglass_empty_black_24dp.png deleted file mode 100644 index e63d9cd..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_hourglass_empty_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_hourglass_empty_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_hourglass_empty_white_24dp.png deleted file mode 100644 index 35b7eef..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_hourglass_empty_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_launch_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_launch_black_24dp.png deleted file mode 100644 index 4ebc46b..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_launch_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_launch_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_launch_white_24dp.png deleted file mode 100644 index a2caac5..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_launch_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_lock_open_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_lock_open_white_24dp.png deleted file mode 100644 index cbe9e1c..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_lock_open_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_lock_outline_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_lock_outline_white_24dp.png deleted file mode 100644 index e2d1091..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_lock_outline_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_lock_outline_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_lock_outline_white_24dp_60.png deleted file mode 100644 index 0b61001..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_lock_outline_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_pause_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_pause_black_24dp.png deleted file mode 100644 index 74068ea..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_pause_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_pause_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_pause_white_24dp.png deleted file mode 100644 index f49aed7..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_pause_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_perm_data_setting_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_perm_data_setting_black_24dp.png deleted file mode 100644 index a8a97f2..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_perm_data_setting_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_perm_data_setting_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_perm_data_setting_white_24dp.png deleted file mode 100644 index e444922..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_perm_data_setting_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_perm_identity_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_perm_identity_white_24dp.png deleted file mode 100644 index e344ea9..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_perm_identity_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_play_arrow_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_play_arrow_black_24dp.png deleted file mode 100644 index f208795..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_play_arrow_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_play_arrow_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_play_arrow_white_24dp.png deleted file mode 100644 index a3c80e7..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_play_arrow_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_search_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_search_white_24dp.png deleted file mode 100644 index bfc3e39..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_search_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_security_color_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_security_color_24dp.png deleted file mode 100644 index 6f25407..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_security_color_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_security_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_security_white_24dp.png deleted file mode 100644 index 7e306c3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_security_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_security_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_security_white_24dp_60.png deleted file mode 100644 index 8ed175d..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_security_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_settings_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_settings_black_24dp.png deleted file mode 100644 index e84e188..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_settings_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_settings_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_settings_white_24dp.png deleted file mode 100644 index 5caedc8..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_settings_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_shopping_cart_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_shopping_cart_black_24dp.png deleted file mode 100644 index 3da6027..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_shopping_cart_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_shopping_cart_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_shopping_cart_white_24dp.png deleted file mode 100644 index 16b6cd0..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_shopping_cart_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_cellular_4_bar_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_cellular_4_bar_white_24dp.png deleted file mode 100644 index 62501b0..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_cellular_4_bar_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_cellular_off_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_cellular_off_white_24dp.png deleted file mode 100644 index 8ed814e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_cellular_off_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_wifi_4_bar_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_wifi_4_bar_white_24dp.png deleted file mode 100644 index 28b5afa..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_wifi_4_bar_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_wifi_off_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_wifi_off_white_24dp.png deleted file mode 100644 index 480145c..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_signal_wifi_off_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_sort_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_sort_white_24dp.png deleted file mode 100644 index 6d4af1b..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xhdpi/ic_sort_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_add_circle_outline_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_add_circle_outline_white_24dp.png deleted file mode 100644 index fdad9ba..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_add_circle_outline_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_attach_money_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_attach_money_black_24dp.png deleted file mode 100644 index a9478a6..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_attach_money_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_attach_money_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_attach_money_white_24dp.png deleted file mode 100644 index d4bde81..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_attach_money_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_check_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_check_white_24dp.png deleted file mode 100644 index 2c2ad77..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_check_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_close_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_close_white_24dp.png deleted file mode 100644 index 6b717e0..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_close_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_cloud_upload_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_cloud_upload_white_24dp.png deleted file mode 100644 index 3ff57ad..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_cloud_upload_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_delete_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_delete_black_24dp.png deleted file mode 100644 index 6d7cb81..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_delete_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_delete_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_delete_white_24dp.png deleted file mode 100644 index 3fcdfdb..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_delete_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_equalizer_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_equalizer_white_24dp.png deleted file mode 100644 index d603c4f..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_equalizer_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_equalizer_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_equalizer_white_24dp_60.png deleted file mode 100644 index f23c2db..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_equalizer_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_error_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_error_white_24dp.png deleted file mode 100644 index abe2573..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_error_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_less_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_less_black_24dp.png deleted file mode 100644 index ee92f4e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_less_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_less_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_less_white_24dp.png deleted file mode 100644 index 62fc386..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_less_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_more_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_more_black_24dp.png deleted file mode 100644 index 5cd142c..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_more_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_more_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_more_white_24dp.png deleted file mode 100644 index dbc0b20..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_expand_more_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_file_download_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_file_download_white_24dp.png deleted file mode 100644 index 78aa591..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_file_download_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_filter_list_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_filter_list_white_24dp.png deleted file mode 100644 index 1263ae8..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_filter_list_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_filter_list_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_filter_list_white_24dp_60.png deleted file mode 100644 index cf26ba5..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_filter_list_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_hourglass_empty_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_hourglass_empty_black_24dp.png deleted file mode 100644 index 47efe9d..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_hourglass_empty_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_hourglass_empty_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_hourglass_empty_white_24dp.png deleted file mode 100644 index 8f67bc6..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_hourglass_empty_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_launch_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_launch_black_24dp.png deleted file mode 100644 index 4305f56..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_launch_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_launch_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_launch_white_24dp.png deleted file mode 100644 index 2ed5b0e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_launch_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_lock_open_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_lock_open_white_24dp.png deleted file mode 100644 index 1d1b0f4..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_lock_open_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_lock_outline_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_lock_outline_white_24dp.png deleted file mode 100644 index bd2cf4d..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_lock_outline_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_lock_outline_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_lock_outline_white_24dp_60.png deleted file mode 100644 index 16e2fc3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_lock_outline_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_pause_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_pause_black_24dp.png deleted file mode 100644 index bb707ea..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_pause_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_pause_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_pause_white_24dp.png deleted file mode 100644 index 7192ad4..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_pause_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_perm_data_setting_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_perm_data_setting_black_24dp.png deleted file mode 100644 index d9e712d..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_perm_data_setting_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_perm_data_setting_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_perm_data_setting_white_24dp.png deleted file mode 100644 index 60257de..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_perm_data_setting_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_perm_identity_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_perm_identity_white_24dp.png deleted file mode 100644 index b08402a..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_perm_identity_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_play_arrow_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_play_arrow_black_24dp.png deleted file mode 100644 index 5345ee3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_play_arrow_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png deleted file mode 100644 index 547ef30..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_play_arrow_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_search_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_search_white_24dp.png deleted file mode 100644 index abbb989..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_search_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_security_color_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_security_color_24dp.png deleted file mode 100644 index c0950f3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_security_color_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_security_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_security_white_24dp.png deleted file mode 100644 index 7bcb2fd..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_security_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_security_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_security_white_24dp_60.png deleted file mode 100644 index e8f3b25..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_security_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_settings_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_settings_black_24dp.png deleted file mode 100644 index 3023ff8..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_settings_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_settings_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_settings_white_24dp.png deleted file mode 100644 index eabb0a2..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_settings_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_shopping_cart_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_shopping_cart_black_24dp.png deleted file mode 100644 index f9121f5..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_shopping_cart_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_shopping_cart_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_shopping_cart_white_24dp.png deleted file mode 100644 index bcfb493..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_shopping_cart_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_cellular_4_bar_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_cellular_4_bar_white_24dp.png deleted file mode 100644 index b191b9d..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_cellular_4_bar_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_cellular_off_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_cellular_off_white_24dp.png deleted file mode 100644 index dedee39..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_cellular_off_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_wifi_4_bar_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_wifi_4_bar_white_24dp.png deleted file mode 100644 index f4105ec..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_wifi_4_bar_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_wifi_off_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_wifi_off_white_24dp.png deleted file mode 100644 index f2023bf..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_signal_wifi_off_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_sort_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_sort_white_24dp.png deleted file mode 100644 index b8ef105..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxhdpi/ic_sort_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_add_circle_outline_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_add_circle_outline_white_24dp.png deleted file mode 100644 index 573aefe..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_add_circle_outline_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_attach_money_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_attach_money_black_24dp.png deleted file mode 100644 index 49956bf..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_attach_money_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_attach_money_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_attach_money_white_24dp.png deleted file mode 100644 index f3c5685..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_attach_money_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_check_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_check_white_24dp.png deleted file mode 100644 index d670618..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_check_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_close_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_close_white_24dp.png deleted file mode 100644 index 3964192..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_close_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_cloud_upload_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_cloud_upload_white_24dp.png deleted file mode 100644 index 2180f73..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_cloud_upload_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_delete_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_delete_black_24dp.png deleted file mode 100644 index f2b75c3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_delete_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_delete_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_delete_white_24dp.png deleted file mode 100644 index 8d322aa..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_delete_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_equalizer_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_equalizer_white_24dp.png deleted file mode 100644 index fa8d522..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_equalizer_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_equalizer_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_equalizer_white_24dp_60.png deleted file mode 100644 index 31cee03..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_equalizer_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_error_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_error_white_24dp.png deleted file mode 100644 index 830fb7e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_error_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_less_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_less_black_24dp.png deleted file mode 100644 index 99c6e3e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_less_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_less_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_less_white_24dp.png deleted file mode 100644 index 4261551..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_less_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_more_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_more_black_24dp.png deleted file mode 100644 index ad852e3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_more_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_more_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_more_white_24dp.png deleted file mode 100644 index 2859a6f..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_expand_more_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_file_download_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_file_download_white_24dp.png deleted file mode 100644 index ded5652..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_file_download_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_filter_list_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_filter_list_white_24dp.png deleted file mode 100644 index cb2207f..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_filter_list_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_filter_list_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_filter_list_white_24dp_60.png deleted file mode 100644 index e66a5d9..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_filter_list_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_hourglass_empty_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_hourglass_empty_black_24dp.png deleted file mode 100644 index 74b4072..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_hourglass_empty_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_hourglass_empty_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_hourglass_empty_white_24dp.png deleted file mode 100644 index b0bda26..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_hourglass_empty_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_launch_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_launch_black_24dp.png deleted file mode 100644 index 4eb7b16..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_launch_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_launch_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_launch_white_24dp.png deleted file mode 100644 index bab25f3..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_launch_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_lock_open_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_lock_open_white_24dp.png deleted file mode 100644 index 8ab4107..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_lock_open_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_lock_outline_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_lock_outline_white_24dp.png deleted file mode 100644 index de1d564..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_lock_outline_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_lock_outline_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_lock_outline_white_24dp_60.png deleted file mode 100644 index 9f3f1f7..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_lock_outline_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_pause_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_pause_black_24dp.png deleted file mode 100644 index 792104f..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_pause_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_pause_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_pause_white_24dp.png deleted file mode 100644 index 660ac65..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_pause_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_perm_data_setting_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_perm_data_setting_black_24dp.png deleted file mode 100644 index a451d53..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_perm_data_setting_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_perm_data_setting_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_perm_data_setting_white_24dp.png deleted file mode 100644 index 1916017..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_perm_data_setting_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_perm_identity_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_perm_identity_white_24dp.png deleted file mode 100644 index 9717ab4..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_perm_identity_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_play_arrow_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_play_arrow_black_24dp.png deleted file mode 100644 index d12d495..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_play_arrow_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_play_arrow_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_play_arrow_white_24dp.png deleted file mode 100644 index be5c062..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_play_arrow_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_search_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_search_white_24dp.png deleted file mode 100644 index dd5adfc..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_search_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_security_color_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_security_color_24dp.png deleted file mode 100644 index 194e70a..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_security_color_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_security_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_security_white_24dp.png deleted file mode 100644 index b1eddbd..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_security_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_security_white_24dp_60.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_security_white_24dp_60.png deleted file mode 100644 index f226c1b..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_security_white_24dp_60.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_settings_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_settings_black_24dp.png deleted file mode 100644 index 476d5c9..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_settings_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_settings_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_settings_white_24dp.png deleted file mode 100644 index 507c5ed..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_settings_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_shopping_cart_black_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_shopping_cart_black_24dp.png deleted file mode 100644 index 6edc956..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_shopping_cart_black_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_shopping_cart_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_shopping_cart_white_24dp.png deleted file mode 100644 index 8c3323e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_shopping_cart_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_cellular_4_bar_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_cellular_4_bar_white_24dp.png deleted file mode 100644 index 4a3ac28..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_cellular_4_bar_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_cellular_off_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_cellular_off_white_24dp.png deleted file mode 100644 index b6adb4e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_cellular_off_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_wifi_4_bar_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_wifi_4_bar_white_24dp.png deleted file mode 100644 index 58a4f9c..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_wifi_4_bar_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_wifi_off_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_wifi_off_white_24dp.png deleted file mode 100644 index 6df209e..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_signal_wifi_off_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_sort_white_24dp.png b/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_sort_white_24dp.png deleted file mode 100644 index 4796c33..0000000 Binary files a/NetworkGenie/app/src/main/main/res/drawable-xxxhdpi/ic_sort_white_24dp.png and /dev/null differ diff --git a/NetworkGenie/app/src/main/main/res/drawable/baseline_file_copy_24.xml b/NetworkGenie/app/src/main/main/res/drawable/baseline_file_copy_24.xml deleted file mode 100644 index f52fd86..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/baseline_file_copy_24.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - diff --git a/NetworkGenie/app/src/main/main/res/drawable/expander_black.xml b/NetworkGenie/app/src/main/main/res/drawable/expander_black.xml deleted file mode 100644 index c9b36b1..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/expander_black.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/expander_white.xml b/NetworkGenie/app/src/main/main/res/drawable/expander_white.xml deleted file mode 100644 index 7a2a352..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/expander_white.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/host_allowed.xml b/NetworkGenie/app/src/main/main/res/drawable/host_allowed.xml deleted file mode 100644 index 5ecc890..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/host_allowed.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/host_blocked.xml b/NetworkGenie/app/src/main/main/res/drawable/host_blocked.xml deleted file mode 100644 index 7ed46a8..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/host_blocked.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/lockdown.xml b/NetworkGenie/app/src/main/main/res/drawable/lockdown.xml deleted file mode 100644 index bcb8f1a..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/lockdown.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/NetworkGenie/app/src/main/main/res/drawable/lockdown_disabled.xml b/NetworkGenie/app/src/main/main/res/drawable/lockdown_disabled.xml deleted file mode 100644 index 3c12ace..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/lockdown_disabled.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/lockdown_off.xml b/NetworkGenie/app/src/main/main/res/drawable/lockdown_off.xml deleted file mode 100644 index b411d82..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/lockdown_off.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/lockdown_on.xml b/NetworkGenie/app/src/main/main/res/drawable/lockdown_on.xml deleted file mode 100644 index dca4c4d..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/lockdown_on.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/other.xml b/NetworkGenie/app/src/main/main/res/drawable/other.xml deleted file mode 100644 index 8ddba52..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/other.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/other_off.xml b/NetworkGenie/app/src/main/main/res/drawable/other_off.xml deleted file mode 100644 index e3bf1ed..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/other_off.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/other_off_disabled.xml b/NetworkGenie/app/src/main/main/res/drawable/other_off_disabled.xml deleted file mode 100644 index 6e1f626..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/other_off_disabled.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/other_on.xml b/NetworkGenie/app/src/main/main/res/drawable/other_on.xml deleted file mode 100644 index 1ee225f..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/other_on.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/other_on_disabled.xml b/NetworkGenie/app/src/main/main/res/drawable/other_on_disabled.xml deleted file mode 100644 index 3ea13c9..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/other_on_disabled.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/screen.xml b/NetworkGenie/app/src/main/main/res/drawable/screen.xml deleted file mode 100644 index 43e91df..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/screen.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/screen_on.xml b/NetworkGenie/app/src/main/main/res/drawable/screen_on.xml deleted file mode 100644 index 5abceeb..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/screen_on.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/screen_on_disabled.xml b/NetworkGenie/app/src/main/main/res/drawable/screen_on_disabled.xml deleted file mode 100644 index dec83be..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/screen_on_disabled.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/wifi.xml b/NetworkGenie/app/src/main/main/res/drawable/wifi.xml deleted file mode 100644 index f042007..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/wifi.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/wifi_off.xml b/NetworkGenie/app/src/main/main/res/drawable/wifi_off.xml deleted file mode 100644 index 27ffd67..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/wifi_off.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/wifi_off_disabled.xml b/NetworkGenie/app/src/main/main/res/drawable/wifi_off_disabled.xml deleted file mode 100644 index f006648..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/wifi_off_disabled.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/wifi_on.xml b/NetworkGenie/app/src/main/main/res/drawable/wifi_on.xml deleted file mode 100644 index 8653752..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/wifi_on.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/drawable/wifi_on_disabled.xml b/NetworkGenie/app/src/main/main/res/drawable/wifi_on_disabled.xml deleted file mode 100644 index d20f995..0000000 --- a/NetworkGenie/app/src/main/main/res/drawable/wifi_on_disabled.xml +++ /dev/null @@ -1,4 +0,0 @@ - - \ No newline at end of file diff --git a/NetworkGenie/app/src/main/main/res/layout/about.xml b/NetworkGenie/app/src/main/main/res/layout/about.xml deleted file mode 100644 index 34ca746..0000000 --- a/NetworkGenie/app/src/main/main/res/layout/about.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - -