This commit is contained in:
bg443
2024-08-18 16:28:44 +01:00
commit 4fcf0df59c
139 changed files with 7252 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
name: Bug Report
about: File a bug report
title: '[Bug]: '
body:
- type: checkboxes
id: prerequisites
attributes:
label: "Please confirm that:"
options:
- label: I have searched the [issues](https://codeberg.org/bg443/JetBird/issues) and didn't find my bug or an answer to my question
required: true
- label: My bug is about JetBird and not something upstream
required: true
- type: input
id: version
attributes:
label: What is your JetBird version?
description: |
This can be found at the bottom of the Settings page.
placeholder: e.g. 1.0.0
validations:
required: true
- type: input
id: model
attributes:
label: What make/model is your device?
placeholder: e.g. Pixel 9 Pro Fold
validations:
required: true
- type: input
id: os
attributes:
label: What OS and version are you running?
placeholder: e.g. GrapheneOS Android 14 (2024071200)
validations:
required: true
- type: textarea
id: bug
attributes:
label: What happened?
description: |
Please include as much detail as possible, as well as steps to reproduce if possible.
validations:
required: true
- type: textarea
id: logs
attributes:
label: Logs
description: |
Please copy and paste any relevant logs. This will be automatically formatted into code, so no need for backticks.
render: shell

View File

@@ -0,0 +1,19 @@
name: Feature Request
about: Submit a feature request
title: '[Feature Request]: '
body:
- type: checkboxes
id: prerequisites
attributes:
label: "Please confirm that:"
options:
- label: I have searched the [issues](https://codeberg.org/bg443/JetBird/issues) and didn't find the feature I am looking for
required: true
- type: textarea
id: feature
attributes:
label: Feature description
description: |
Please include as much detail as possible.
validations:
required: true

137
.gitignore vendored Normal file
View File

@@ -0,0 +1,137 @@
### AndroidStudio ###
# Covers files to be ignored for android development using Android Studio.
# Built application files
*.apk
*.ap_
*.aab
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle
.gradle/
build/
# Signing files
.signing/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio
/*/build/
/*/local.properties
/*/out
/*/*/build
/*/*/production
captures/
.navigation/
*.ipr
*~
*.swp
# Keystore files
*.jks
*.keystore
# Google Services (e.g. APIs or Firebase)
# google-services.json
# Android Patch
gen-external-apklibs
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
# NDK
obj/
# IntelliJ IDEA
*.iml
*.iws
/out/
# User-specific configurations
.idea/caches/
.idea/libraries/
.idea/shelf/
.idea/workspace.xml
.idea/tasks.xml
.idea/.name
.idea/compiler.xml
.idea/copyright/profiles_settings.xml
.idea/encodings.xml
.idea/misc.xml
.idea/modules.xml
.idea/scopes/scope_settings.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
.idea/datasources.xml
.idea/dataSources.ids
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
.idea/assetWizardSettings.xml
.idea/gradle.xml
.idea/jarRepositories.xml
.idea/navEditor.xml
.idea/deploymentTargetSelector.xml
.idea/appInsightsSettings.xml
.idea/other.xml
# Legacy Eclipse project files
.classpath
.project
.cproject
.settings/
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.war
*.ear
# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml)
hs_err_pid*
## Plugin-specific files:
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Mongo Explorer plugin
.idea/mongoSettings.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
### AndroidStudio Patch ###
!/gradle/wrapper/gradle-wrapper.jar
### Netbird ###
lib/*.*ar

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "netbird"]
path = netbird
url = https://github.com/netbirdio/netbird.git

3
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

123
.idea/codeStyles/Project.xml generated Normal file
View File

@@ -0,0 +1,123 @@
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JetCodeStyleSettings>
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</JetCodeStyleSettings>
<codeStyleSettings language="XML">
<option name="FORCE_REARRANGE_MODE" value="1" />
<indentOptions>
<option name="CONTINUATION_INDENT_SIZE" value="4" />
</indentOptions>
<arrangement>
<rules>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:android</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>xmlns:.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:id</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*:name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>name</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>style</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>^$</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
</AND>
</match>
<order>ANDROID_ATTRIBUTE_ORDER</order>
</rule>
</section>
<section>
<rule>
<match>
<AND>
<NAME>.*</NAME>
<XML_ATTRIBUTE />
<XML_NAMESPACE>.*</XML_NAMESPACE>
</AND>
</match>
<order>BY_NAME</order>
</rule>
</section>
</rules>
</arrangement>
</codeStyleSettings>
<codeStyleSettings language="kotlin">
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
</codeStyleSettings>
</code_scheme>
</component>

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View File

@@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>

10
.idea/deploymentTargetDropDown.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetDropDown">
<value>
<entry key="app">
<State />
</entry>
</value>
</component>
</project>

View File

@@ -0,0 +1,41 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
<option name="previewFile" value="true" />
</inspection_tool>
</profile>
</component>

6
.idea/kotlinc.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="2.0.10" />
</component>
</project>

10
.idea/migrations.xml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectMigrations">
<option name="MigrateToGradleLocalJavaHome">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</component>
</project>

43
.woodpecker.yml Normal file
View File

@@ -0,0 +1,43 @@
steps:
build_netbird:
image: openpriv/go-cross-compile:2024.02
commands:
- ./scripts/build_netbird.sh -v
build_debug:
image: alvrme/alpine-android:android-34-jdk21
commands:
- ./gradlew :app:assembleDebug
when:
path: [app/**, build.gradle.kts, .woodpecker.yml]
event: [push]
build_release:
image: alvrme/alpine-android:android-34-jdk21
commands:
- ./gradlew :app:assembleRelease --stacktrace
when:
event: [tag]
sign:
image: alvrme/alpine-android:android-34-jdk21
commands:
- ./scripts/apk_sign.sh
secrets: [APK_KS, APK_KS_ALIAS, APK_KS_PASS]
when:
event: [tag]
publish:
image: woodpeckerci/plugin-gitea-release
settings:
base_url: https://codeberg.org
files:
- JetBird-arm64-v8a-release.apk
- JetBird-armeabi-v7a-release.apk
- JetBird-universal-release.apk
- JetBird-x86-release.apk
- JetBird-x86_64-release.apk
api_key:
from_secret: GIT_ACCESS_TOKEN
target: master
prerelease: true
when:
event: [tag]
when:
event: [push, tag, pull_request]

675
LICENCE.md Normal file
View File

@@ -0,0 +1,675 @@
# GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
<https://fsf.org/>
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 <https://www.gnu.org/licenses/>.
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:
<program> Copyright (C) <year> <name of author>
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 <https://www.gnu.org/licenses/>.
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 <https://www.gnu.org/licenses/why-not-lgpl.html>.

117
README.md Normal file
View File

@@ -0,0 +1,117 @@
<div align="center">
<img src="assets/jetbird_banner_full_rev4.svg" alt="JetBird banner" />
[![status-badge](https://ci.codeberg.org/api/badges/status.svg)]()
[![Submodule SHA](https://badges.codeberg.org/badge/dynamic/json?url=https%3A%2F%2Fcodeberg.org%2Fapi%2Fv1%2Frepos%2Fbg443%2FJetBird%2Fcontents%2Fnetbird&query=%24.sha&label=submodule%20commit%20SHA)]()
[![Upstream Release](https://badges.codeberg.org/github/v/release/netbirdio/netbird?label=latest%20upstream%20release)](https://github.com/netbirdio/netbird/releases/latest)
[![GitHub commits since latest release](https://badges.codeberg.org/github/commits-since/netbirdio/netbird/latest)](https://github.com/netbirdio/netbird)
<p>An unofficial, FLOSS, native Android NetBird client built with privacy in mind</p>
</div>
## About
JetBird is an implementation of the NetBird client for Android.
It has been built with privacy in mind and contains no blobs or trackers.
## Features
- Native UI
- Use SSO or setup keys
- Use pre-shared keys
- See all logs in real time
- Quick tile
- Exclude apps from the tunnel
- Exit nodes (with client-side customisation)
- Tablet support
## Differences
There are a few differences between NetBird official Android client and JetBird. Some of these features rely on patches to the NetBird source (these are in `patches/`):
- See all peer info
- Use setup keys even with SSO support
- Rosenpass support
- Split tunneling via routes and/or per app
- l18n
## Install
### Prebuilt binaries
- Available to download in the [releases](https://codeberg.org/bg443/JetBird/releases) tab
- You can see the steps of the build on [JetBird's CI page]()
- Where possible, download the specific build for your device's architecture because the NetBird client is ~35-40MB and downloading the universal version will download all 4 architectures regardless of if you need them
<br />
<div>
<a href="https://codeberg.org/bg443/JetBird/releases" rel="noopener noreferrer" target=_blank><img src="./assets/codeberg.svg" height=60 alt="Get it on Codeberg" /></a>&nbsp;&nbsp;&nbsp;
<a href="https://github.com/ImranR98/Obtainium" rel="noopener noreferrer" target="_blank"> <img src="./assets/badge_obtainium.png" height="60" alt="Get it on Obtainium" /></a>&nbsp;&nbsp;&nbsp;
<a href="https://codeberg.org/bg443/JetBird/releases.rss" rel="noopener noreferrer" target=_blank><img src="./assets/RSS.svg" height=60 alt="Follow with RSS" /></a>
</div>
### Build from source
1. Build NetBird
```
./scripts/build_netbird.sh
```
JetBird's NetBird client patches will be applied automatically.
2. Build APK
```
./gradlew :app:assembleRelease
```
## Privacy
JetBird does not, and never will, call home.
JetBird/NetBird has to talk to your management server, which will have it's own privacy policy.
In the NetBird management portal, admins will be able to see:
- You are using JetBird
- JetBird and NetBird versions
- Device model e.g. Pixel 9 Pro Fold
- Operating system e.g. Android 14
JetBird makes no extra connections or requests outside of the NetBird client.
## Permissions
JetBird requires a few permissions in order to function:
- `INTERNET`
- `FOREGROUND_SERVICE`/`FOREGROUND_SERVICE_SYSTEM_EXEMPTED` - used to run the VPN service
- `ACCESS_NETWORK_STATE`/`CHANGE_NETWORK_STATE` - used to monitor network to check if VPN is already running etc.
- `QUERY_ALL_PACKAGES` - used so you can choose which apps aren't tunneled
## Screenshots
### Phone
<div align="center">
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/1.png" alt="" loading="lazy" width="20%" />
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/2.png" alt="" loading="lazy" width="20%" />
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/3.png" alt="" loading="lazy" width="20%" />
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/4.png" alt="" loading="lazy" width="20%" />
<img src="fastlane/metadata/android/en-US/images/phoneScreenshots/5.png" alt="" loading="lazy" width="20%" />
</div>
### Tablet
<div align="center">
<img src="fastlane/metadata/android/en-US/images/tenInchScreenshots/1.png" alt="" loading="lazy" width="50%" />
<img src="fastlane/metadata/android/en-US/images/tenInchScreenshots/2.png" alt="" loading="lazy" width="50%" />
<img src="fastlane/metadata/android/en-US/images/tenInchScreenshots/3.png" alt="" loading="lazy" width="50%" />
<img src="fastlane/metadata/android/en-US/images/tenInchScreenshots/4.png" alt="" loading="lazy" width="50%" />
</div>
## Issues
As JetBird is just a wrapper around the official NetBird client, most connection/peer/management issues will reside with upstream.
Please open an issue using the template provided if you believe you have found a bug or have a feature request!
## Libraries
See a full list of libraries used [here](https://codeberg.org/bg443/JetBird/wiki/Libraries)
## License
<img src="assets/gpl_v3.svg" height=100 />
<br />
JetBird is free software: you can redistribute it and/or modify it under the terms of the [GNU GPL-3.0-or-later License](./LICENCE.md) as published by the Free Software Foundation.
This software is provided with no warranty.
## Other
"NetBird" and the "NetBird" logo are <a href="https://netbird.io/terms" rel="noopener noreferrer" target=_blank>copyright</a> owned by or licensed to Wiretrustee UG.
"WireGuard" and the "WireGuard" logo are registered <a href="https://www.wireguard.com/trademark-policy" rel="noopener noreferrer" target=_blank>trademarks</a> of Jason A. Donenfeld.

1
app/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

130
app/build.gradle.kts Normal file
View File

@@ -0,0 +1,130 @@
import java.io.ByteArrayOutputStream
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.ksp)
alias(libs.plugins.hilt)
}
android {
namespace = "dev.bg.jetbird"
compileSdk = 34
defaultConfig {
applicationId = "dev.bg.jetbird"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0.0"
buildConfigField("String", "NETBIRD_COMMIT", getNetbirdCommit())
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["disableAnalytics"] = "true"
vectorDrawables {
useSupportLibrary = true
}
}
buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("debug")
}
}
splits {
abi {
isEnable = true
reset()
include("x86", "x86_64", "armeabi-v7a", "arm64-v8a")
isUniversalApk = true
}
}
dependenciesInfo {
includeInApk = false
includeInBundle = false
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
kotlinOptions {
jvmTarget = "21"
}
buildFeatures {
compose = true
buildConfig = true
}
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
}
}
dependencies {
coreLibraryDesugaring(libs.desugarJdkLibs)
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(platform(libs.androidx.compose.bom))
// Netbird binding
implementation(projects.lib)
// UI
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.androidx.material3.adaptive)
implementation(libs.androidx.material3.adaptive.layout)
implementation(libs.androidx.material3.adaptive.navigation)
// Dependency Injection
implementation(libs.bundles.hilt)
ksp(libs.hilt.androidx.compiler)
ksp(libs.hilt.compiler)
// Preferences
implementation(libs.mmkv)
// Logging
implementation(libs.timber)
// Misc
implementation(libs.ipaddress)
debugImplementation(libs.leakCanary)
// Test
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}
configurations.all {
exclude("com.google.android.gms") // Just in case
}
fun getNetbirdCommit(): String {
val stdout = ByteArrayOutputStream()
exec {
commandLine("git", "submodule", "status")
standardOutput = stdout
}
return "\"${stdout.toString().trim().split(" ").first().take(10).dropWhile { c -> c == '+' }}\""
}

4
app/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,4 @@
-optimizationpasses 5
-allowaccessmodification
-dontobfuscate
-dontpreverify # not useful for Android

View File

@@ -0,0 +1,16 @@
package dev.bg.jetbird
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("dev.bg.jetbird", appContext.packageName)
}
}

View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SYSTEM_EXEMPTED" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
<application
android:name=".JetBird"
android:allowBackup="false"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.JetBird"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:theme="@style/Theme.JetBird">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name=".service.VPNService"
android:permission="android.permission.BIND_VPN_SERVICE"
android:foregroundServiceType="systemExempted"
android:enabled="true"
android:exported="false"
android:stopWithTask="false"
tools:ignore="ForegroundServicePermission">
<intent-filter>
<action android:name="android.net.VpnService" />
</intent-filter>
<property
android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
android:value="vpn" />
<meta-data
android:name="android.net.VpnService.SUPPORTS_ALWAYS_ON"
android:value="true" />
</service>
<service android:name=".service.Tile"
android:exported="true"
android:label="@string/app_name"
android:icon="@drawable/ic_tile"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
<meta-data
android:name="android.service.quicksettings.ACTIVE_TILE"
android:value="false" />
<meta-data
android:name="android.service.quicksettings.TOGGLEABLE_TILE"
android:value="true" />
</service>
</application>
</manifest>

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

@@ -0,0 +1,19 @@
package dev.bg.jetbird
import android.app.Application
import com.tencent.mmkv.MMKV
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber
@HiltAndroidApp
class JetBird: Application() {
override fun onCreate() {
super.onCreate()
MMKV.initialize(this)
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
}
}

View File

@@ -0,0 +1,110 @@
package dev.bg.jetbird
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.net.VpnService
import android.os.Bundle
import android.os.IBinder
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import dagger.hilt.android.AndroidEntryPoint
import dev.bg.jetbird.data.LayoutType
import dev.bg.jetbird.service.VPNService
import dev.bg.jetbird.ui.Navigation
import dev.bg.jetbird.ui.theme.JetBirdTheme
import dev.bg.jetbird.util.OnLayoutChange
import dev.bg.jetbird.util.ktx.hasOtherAlwaysOnVpn
import timber.log.Timber
val LocalNavController = staticCompositionLocalOf<NavHostController> { error("No NavController") }
val LocalVPNServiceBinder = staticCompositionLocalOf<VPNService.VPNServiceBinder?> { error("No VPNService") }
val LocalServiceConnection = staticCompositionLocalOf<ServiceConnection> { error("No ServiceConnection") }
val LocalSnackbar = staticCompositionLocalOf<SnackbarHostState> { error("No SnackbarHostState") }
val LocalLayoutType = staticCompositionLocalOf<LayoutType> { error("No LayoutType") }
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
private var binder by mutableStateOf<VPNService.VPNServiceBinder?>(null)
private val serviceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
if (service is VPNService.VPNServiceBinder) {
Timber.d("Bound service")
binder = service
// binder?.startClientListener()
}
}
override fun onServiceDisconnected(name: ComponentName?) {
// binder?.stopClientListener()
binder = null
}
}
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
val intent = VpnService.prepare(this);
if (!hasOtherAlwaysOnVpn() && intent != null) {
Timber.d("JetBird has all permissions - auto-starting service")
val i = Intent(this, VPNService::class.java)
startService(i)
bindService(i, serviceConnection, Context.BIND_AUTO_CREATE)
}
setContent {
JetBirdTheme {
val navController = rememberNavController()
val snackbarHostState = remember { SnackbarHostState() }
var layoutType by remember { mutableStateOf(LayoutType.CompactPortrait) }
OnLayoutChange {
layoutType = it
}
CompositionLocalProvider(
LocalNavController provides navController,
LocalVPNServiceBinder provides binder,
LocalServiceConnection provides serviceConnection,
LocalSnackbar provides snackbarHostState,
LocalLayoutType provides layoutType
) {
Navigation()
}
}
}
}
override fun onResume() {
super.onResume()
// TODO check if running
if (binder == null) {
bindService(
Intent(this, VPNService::class.java),
serviceConnection, Context.BIND_AUTO_CREATE
)
}
}
override fun onDestroy() {
if (binder != null) {
unbindService(serviceConnection)
}
super.onDestroy()
}
}

View File

@@ -0,0 +1,34 @@
package dev.bg.jetbird
import androidx.compose.runtime.Immutable
enum class ScaffoldVisibility {
Gone,
Top,
NavOnly,
ActionsOnly
}
@Immutable
sealed class Route(
val route: String
) {
data object Home: Route("home")
data object Setup: Route("setup")
data object Log: Route("log")
data object Settings: Route("settings")
data object RouteSelector: Route("route_selector")
data object Credits: Route("credits")
companion object {
fun getScaffoldVisibility(route: String?): ScaffoldVisibility = when (route) {
Home.route -> ScaffoldVisibility.ActionsOnly
Setup.route -> ScaffoldVisibility.Gone
Log.route -> ScaffoldVisibility.NavOnly
Settings.route -> ScaffoldVisibility.NavOnly
RouteSelector.route -> ScaffoldVisibility.NavOnly
Credits.route -> ScaffoldVisibility.NavOnly
else -> ScaffoldVisibility.Gone
}
}
}

View File

@@ -0,0 +1,27 @@
package dev.bg.jetbird.data
import android.graphics.Color
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.Color as ComposeColor
@Immutable
object JetBirdColors {
val ErrorRed = ComposeColor(Color.parseColor("#F6685E"))
object IndicatorColors {
val Connected = ComposeColor(Color.parseColor("#CDFAD5"))
val Connecting = ComposeColor(Color.parseColor("#FFCF96"))
val Disconnected = ComposeColor(Color.parseColor("#FF8080"))
}
}
object Actions {
const val ALWAYS_ON_START = "android.net.VpnService"
const val TILE_START_SERVICE_ACTION = "dev.bg.jetbird.Tile.Start"
const val TILE_STOP_SERVICE_ACTION = "dev.bg.jetbird.Tile.Stop"
}
object NetBirdErrors {
const val NETBIRD_TUNNEL_FAILURE = "rpc error: code = PermissionDenied desc = no peer auth method provided, please use a setup key or interactive SSO login"
val all = listOf(NETBIRD_TUNNEL_FAILURE)
}

View File

@@ -0,0 +1,9 @@
package dev.bg.jetbird.data
enum class LayoutType {
CompactPortrait,
WidePortrait,
CompactLandscape,
WideLandscape,
PanelLandscape
}

View File

@@ -0,0 +1,9 @@
package dev.bg.jetbird.data.model
data class CIDR(
private val route: String
) {
private val destructured = route.split("/")
val address = destructured[0]
val mask = destructured[1].toInt()
}

View File

@@ -0,0 +1,8 @@
package dev.bg.jetbird.data.model
enum class ConnectionState {
CONNECTING,
CONNECTED,
DISCONNECTING,
DISCONNECTED,
}

View File

@@ -0,0 +1,9 @@
package dev.bg.jetbird.data.model
sealed class BaseEvent {
abstract val event: String
}
data class ServiceEvent(
override val event: String
): BaseEvent()

View File

@@ -0,0 +1,17 @@
package dev.bg.jetbird.data.model
data class Peer(
val ip: String,
val fqdn: String,
val connectionStatus: String,
val connectionStatusUpdate: String,
val publicKey: String,
val relayed: Boolean,
val direct: Boolean,
val lastWireguardHandshake: String,
val bytesTx: Long,
val bytesRx: Long,
val latency: Long,
val rosenpassEnabled: Boolean,
val routes: List<String>
)

View File

@@ -0,0 +1,6 @@
package dev.bg.jetbird.data.model
data class VPNState(
val connectionState: ConnectionState,
val peers: List<Peer>
)

View File

@@ -0,0 +1,24 @@
package dev.bg.jetbird.di
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dev.bg.jetbird.util.DefaultDispatcher
import dev.bg.jetbird.util.IoDispatcher
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
@Module
@InstallIn(SingletonComponent::class)
object Dispatchers {
@Provides
@DefaultDispatcher
fun provideDefaultDispatcher(): CoroutineDispatcher = Dispatchers.Default
@Provides
@IoDispatcher
fun provideIODispatcher(): CoroutineDispatcher = Dispatchers.IO
}

View File

@@ -0,0 +1,37 @@
package dev.bg.jetbird.di
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import dev.bg.jetbird.repository.LogRepository
import dev.bg.jetbird.repository.LogRepositoryImpl
import dev.bg.jetbird.repository.PreferencesRepository
import dev.bg.jetbird.repository.PreferencesRepositoryImpl
import dev.bg.jetbird.repository.VpnRepository
import dev.bg.jetbird.repository.VpnRepositoryImpl
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
interface RepositoryModule {
@Binds
@Singleton
abstract fun provideLogRepository(
logRepository: LogRepositoryImpl
): LogRepository
@Binds
@Singleton
abstract fun providePreferencesRepository(
preferencesRepository: PreferencesRepositoryImpl
): PreferencesRepository
@Binds
@Singleton
abstract fun provideVpnRepository(
vpnRepositoryImpl: VpnRepositoryImpl
): VpnRepository
}

View File

@@ -0,0 +1,112 @@
package dev.bg.jetbird.lib
import android.content.Context
import android.net.ConnectivityManager
import android.net.ConnectivityManager.NetworkCallback
import android.net.LinkProperties
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Build
import dev.bg.jetbird.util.ktx.addFallbackDns
import dev.bg.jetbird.util.ktx.toDnsList
import io.netbird.android.DNSList
import timber.log.Timber
import java.net.InetAddress
interface DNSListener {
fun onNetworkChanged()
fun onDnsChanged(dnsServers: DNSList)
}
class DNSWatch(
context: Context,
private val dnsListener: DNSListener
): NetworkCallback() {
private val connectivityManager: ConnectivityManager = context.getSystemService(ConnectivityManager::class.java)
private var dnsServers: DNSList
init {
dnsServers = getActiveDns()
}
@get:Synchronized
var isPrivateDnsActive = false
private set
fun getActiveDns(): DNSList {
val activeNetwork = connectivityManager.activeNetwork ?: return DNSList()
val props = connectivityManager.getLinkProperties(activeNetwork) ?: return DNSList()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
isPrivateDnsActive = props.isPrivateDnsActive
}
return extendWithFallbackDNS(props.dnsServers)
}
fun registerNetworkCallback() {
val networkRequest = NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_VPN)
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
.addTransportType(NetworkCapabilities.TRANSPORT_ETHERNET)
.build()
connectivityManager.requestNetwork(networkRequest, this)
}
fun engineHasStopped() {
connectivityManager.unregisterNetworkCallback(this)
}
@Synchronized
private fun onNewDNSList(linkProperties: LinkProperties) {
val newDNSList = extendWithFallbackDNS(linkProperties.dnsServers)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
isPrivateDnsActive = linkProperties.isPrivateDnsActive
}
if (newDNSList.size() != dnsServers.size()) {
try {
notifyDnsWatcher(newDNSList)
dnsServers = newDNSList
} catch (e: Exception) {
Timber.e("Failed to update dns servers $e")
}
return
}
for (i in 0..<newDNSList.size()) {
try {
if (newDNSList[i] != dnsServers[i]) {
notifyDnsWatcher(newDNSList)
dnsServers = newDNSList
return
}
} catch (e: Exception) {
Timber.e("Failed to update dns servers $e")
return
}
}
}
private fun extendWithFallbackDNS(dnsServers: List<InetAddress>): DNSList {
val modifiableDnsServers: List<InetAddress> = ArrayList(dnsServers)
if (dnsServers.isEmpty()) {
return modifiableDnsServers.toDnsList()
}
if (!dnsServers[0].isLinkLocalAddress) {
return modifiableDnsServers.toDnsList()
}
return modifiableDnsServers.addFallbackDns("1.1.1.1")
}
private fun notifyDnsWatcher(dnsServers: DNSList) {
Timber.d("Received DNS update: $dnsServers")
dnsListener.onDnsChanged(dnsServers)
}
override fun onLinkPropertiesChanged(network: Network, linkProperties: LinkProperties) {
onNewDNSList(linkProperties)
dnsListener.onNetworkChanged()
}
}

View File

@@ -0,0 +1,17 @@
package dev.bg.jetbird.lib
import io.netbird.android.IFaceDiscover
import java.net.NetworkInterface
class InterfaceDiscovery: IFaceDiscover {
// e.g. wlan0 26 1500 true true false false true|fe80::74b1:36ff:fe05:ed4c%wlan0/64 10.3.10.199/24
override fun iFaces(): String {
return NetworkInterface.getNetworkInterfaces().toList().joinToString(separator = "\n") { networkInterface ->
"${networkInterface.name} ${networkInterface.index} ${networkInterface.mtu} ${networkInterface.isUp} ${networkInterface.supportsMulticast()} ${networkInterface.isLoopback} ${networkInterface.isPointToPoint} ${networkInterface.supportsMulticast()}|".plus(
networkInterface.interfaceAddresses.joinToString(" ") { interfaceAddress -> "${interfaceAddress.address.hostAddress}/${interfaceAddress.networkPrefixLength}" }
)
}.plus("\n")
}
}

View File

@@ -0,0 +1,249 @@
package dev.bg.jetbird.lib
import android.os.Build
import android.system.OsConstants
import dev.bg.jetbird.BuildConfig
import dev.bg.jetbird.data.model.CIDR
import dev.bg.jetbird.service.VPNService
import dev.bg.jetbird.util.calculateTunneledRoutes
import dev.bg.jetbird.util.ktx.getConfigPath
import io.netbird.android.Android
import io.netbird.android.Client
import io.netbird.android.ConnectionListener
import io.netbird.android.DNSList
import io.netbird.android.NetworkChangeListener
import io.netbird.android.PeerInfoArray
import io.netbird.android.TunAdapter
import io.netbird.android.URLOpener
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
interface TunnelListener {
fun onStarted()
fun onStopped()
fun onRequiresRestart()
fun onLog(message: String, verbose: Boolean, force: Boolean)
fun onError(message: String)
}
enum class EngineLoggingLevel {
None,
Info,
Trace
}
class Tunnel(
private val vpnService: VPNService,
private val tunnelListener: TunnelListener,
private val connectionListener: ConnectionListener
): TunAdapter, NetworkChangeListener, DNSListener {
val dnsWatch: DNSWatch = DNSWatch(vpnService.baseContext, this)
private val scope = CoroutineScope(SupervisorJob())
private val client: Client = Android.newClient(
vpnService.baseContext.getConfigPath(),
Build.MODEL,
"JetBird-${BuildConfig.VERSION_NAME}",
this,
InterfaceDiscovery(),
this
)
private var isRunning = false
private var excludedApps = emptySet<String>()
private var routeOverrideEnabled = false
private var routeOverrides = emptySet<String>()
@Synchronized
fun start(
urlOpener: URLOpener?,
loggingLevel: EngineLoggingLevel,
excludeApps: Set<String>,
enableRouteOverrides: Boolean,
overrides: Set<String>
) {
if (isRunning) return
when (loggingLevel) {
EngineLoggingLevel.Info -> client.setInfoLogLevel()
EngineLoggingLevel.Trace -> client.setTraceLogLevel()
EngineLoggingLevel.None -> client.disableLogs()
}
excludedApps = excludeApps
routeOverrideEnabled = enableRouteOverrides
routeOverrides = overrides
scope.launch {
try {
notifyServiceStateListeners(true)
if (urlOpener == null) {
dnsWatch.registerNetworkCallback()
client.runWithoutLogin(dnsWatch.getActiveDns()) {
log("Netbird DNS ready")
}
} else {
dnsWatch.registerNetworkCallback()
client.run(urlOpener, dnsWatch.getActiveDns()) {
log("Netbird DNS ready")
}
}
} catch (e: Exception) {
log("NetBird error $e", force = true)
notifyError(e)
} finally {
notifyServiceStateListeners(false)
dnsWatch.engineHasStopped()
}
}
}
override fun onDnsChanged(dnsServers: DNSList) {
log("Telling Netbird about new DNS servers", verbose = true)
try {
client.onUpdatedHostDNS(dnsServers)
} catch (e: Exception) {
log("Failed to update DNS servers in client $e")
}
}
fun stop() {
client.stop()
}
fun startClientListener() {
client.setConnectionListener(connectionListener)
}
fun stopClientListener() {
client.removeConnectionListener()
}
fun peersInfo(): PeerInfoArray {
return client.peersList()
}
private fun log(
message: String,
verbose: Boolean = false,
force: Boolean = false
) {
tunnelListener.onLog(message, verbose, force)
}
private fun notifyError(e: Exception) {
tunnelListener.onError(e.message ?: "Unknown error")
}
private fun notifyServiceStateListeners(engineIsRunning: Boolean) {
isRunning = engineIsRunning
if (engineIsRunning) {
tunnelListener.onStarted()
} else {
tunnelListener.onStopped()
}
}
override fun onNetworkChanged(p0: String) {
log("NetBird sent new routes - recreating tunnel")
tunnelListener.onRequiresRestart()
}
override fun setInterfaceIP(ip: String) {}
override fun configureInterface(
cidr: String?,
mtu: Long,
dns: String?,
domains: String?,
routes: String?
): Long {
return try {
log("Adding CIDR block to interface $cidr", verbose = true)
if (cidr == null) {
log("Netbird sent invalid CIDR block")
return 0L
}
val allocatedCidr = CIDR(cidr)
val builder = vpnService.tunnelBuilder
.addAddress(allocatedCidr.address, allocatedCidr.mask)
.allowFamily(OsConstants.AF_INET)
.allowFamily(OsConstants.AF_INET6)
.setMtu(mtu.toInt())
.apply {
if (dns.isNullOrEmpty()) {
log("DNS null")
return@apply
}
if (vpnService.isUsingPrivateDns) {
log("Ignoring DNS because private DNS is active")
return@apply
}
log("Adding DNS: $dns")
addDnsServer(dns)
}
.apply {
when (domains) {
null, "" -> emptyList()
else -> domains.split(";")
}.forEach { domain ->
log("Adding search domain: $domain", verbose = true)
addSearchDomain(domain)
}
val upstreamRoutes = when (routes) {
null, "" -> emptyList()
else -> routes.split(";")
}.toSet()
if (upstreamRoutes.isNotEmpty()) {
if (routeOverrideEnabled && routeOverrides.isNotEmpty()) {
log("Using route overrides")
calculateTunneledRoutes(
allowedIps = upstreamRoutes,
disallowedIps = routeOverrides
).map { CIDR(it) }.forEach { route ->
log("Adding route: ${route.address}/${route.mask}", verbose = true)
addRoute(route.address, route.mask)
}
} else {
log("Using upstream routes")
upstreamRoutes.map { CIDR(it) }.forEach { route ->
log("Adding route: ${route.address}/${route.mask}", verbose = true)
addRoute(route.address, route.mask)
}
}
}
excludedApps.forEach { packageName ->
try {
log("Excluding $packageName from tunnel")
addDisallowedApplication(packageName)
} catch (e: Exception) {
log("Failed to exclude $packageName from tunnel")
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
setMetered(false)
}
setBlocking(true)
}
vpnService.setUnderlyingNetworks(null)
builder.establish().use { tun ->
if (tun == null) {
log("Failed to create tunnel")
return 0L
}
return tun.detachFd().toLong()
}
} catch (e: Exception) {
log("Failed to create tunnel ${e.message}")
0L
}
}
override fun protectSocket(socket: Int): Boolean {
return vpnService.protect(socket)
}
override fun updateAddr(s: String) {}
override fun onNetworkChanged() {
log("Network changed")
}
}

View File

@@ -0,0 +1,33 @@
package dev.bg.jetbird.repository
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import javax.inject.Inject
interface LogRepository {
val logEntries: StateFlow<List<String>>
fun log(message: String)
fun clear()
}
class LogRepositoryImpl @Inject constructor(): LogRepository {
private val _logEntries: MutableStateFlow<List<String>> = MutableStateFlow(emptyList())
override val logEntries: StateFlow<List<String>>
get() = _logEntries.asStateFlow()
override fun log(message: String) {
_logEntries.update {
it.toMutableList().apply {
add(message)
}
}
}
override fun clear() {
_logEntries.update { emptyList() }
}
}

View File

@@ -0,0 +1,190 @@
package dev.bg.jetbird.repository
import com.tencent.mmkv.MMKV
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject
interface PreferencesValues {
// NetBird
var managementUrl: String?
var ssoSupported: Boolean
var hasAuthed: Boolean
var preSharedKey: String?
var setupKey: String?
var rosenpass: Boolean
var rosenpassPermissive: Boolean
var engineLogging: Boolean
var verboseEngineLogging: Boolean
var liveEngineLogging: Boolean
// JetBird
var logging: Boolean
var verboseLogging: Boolean
var excludedApps: Set<String>
var routeOverridesEnabled: Boolean
var routeOverrides: Set<String>
}
interface PreferencesRepository: PreferencesValues {
val state: StateFlow<PreferencesState>
fun reset()
suspend fun updateState()
}
class PreferencesRepositoryImpl @Inject constructor(): PreferencesRepository {
private val mmkv = MMKV.mmkvWithID(PreferenceKeys.ID.key, MMKV.MULTI_PROCESS_MODE)
private val _state: MutableStateFlow<PreferencesState> = MutableStateFlow(this.asState())
override val state: StateFlow<PreferencesState>
get() = _state.asStateFlow()
override suspend fun updateState() {
_state.emit(this.asState())
}
// NetBird
override var managementUrl: String?
get() = mmkv.decodeString(PreferenceKeys.ManagementUrl.key, null)
set(value) { mmkv.encode(PreferenceKeys.ManagementUrl.key, value) }
override var ssoSupported: Boolean
get() = mmkv.decodeBool(PreferenceKeys.SsoSupported.key, false)
set(value) { mmkv.encode(PreferenceKeys.SsoSupported.key, value) }
override var hasAuthed: Boolean
get() = mmkv.decodeBool(PreferenceKeys.HasAuthed.key, false)
set(value) { mmkv.encode(PreferenceKeys.HasAuthed.key, value) }
override var preSharedKey: String?
get() = mmkv.decodeString(PreferenceKeys.PreSharedKey.key, null)
set(value) { mmkv.encode(PreferenceKeys.PreSharedKey.key, value) }
override var setupKey: String?
get() = mmkv.decodeString(PreferenceKeys.SetupKey.key, null)
set(value) { mmkv.encode(PreferenceKeys.SetupKey.key, value) }
override var rosenpass: Boolean
get() = mmkv.decodeBool(PreferenceKeys.Rosenpass.key, false)
set(value) {mmkv.encode(PreferenceKeys.Rosenpass.key, value) }
override var rosenpassPermissive: Boolean
get() = mmkv.decodeBool(PreferenceKeys.RosenpassPermissive.key, false)
set(value) { mmkv.encode(PreferenceKeys.RosenpassPermissive.key, value) }
override var engineLogging: Boolean
get() = mmkv.decodeBool(PreferenceKeys.EngineLogging.key, false)
set(value) {
mmkv.encode(PreferenceKeys.EngineLogging.key, value)
if (!value) {
verboseEngineLogging = false
liveEngineLogging = false
}
}
override var verboseEngineLogging: Boolean
get() = mmkv.decodeBool(PreferenceKeys.VerboseEngineLogging.key, false)
set(value) { mmkv.encode(PreferenceKeys.VerboseEngineLogging.key, value) }
override var liveEngineLogging: Boolean
get() = mmkv.decodeBool(PreferenceKeys.LiveEngineLogging.key, false)
set(value) { mmkv.encode(PreferenceKeys.LiveEngineLogging.key, value) }
// JetBird
override var logging: Boolean
get() = mmkv.decodeBool(PreferenceKeys.Logging.key, false)
set(value) {
mmkv.encode(PreferenceKeys.Logging.key, value)
if (!value) {
verboseLogging = false
}
}
override var verboseLogging: Boolean
get() = mmkv.decodeBool(PreferenceKeys.VerboseLogging.key, false)
set(value) { mmkv.encode(PreferenceKeys.VerboseLogging.key, value) }
override var excludedApps: Set<String>
get() = mmkv.decodeStringSet(PreferenceKeys.ExcludedApps.key, emptySet<String>())!!.toSet()
set(value) { mmkv.encode(PreferenceKeys.ExcludedApps.key, value) }
override var routeOverridesEnabled: Boolean
get() = mmkv.decodeBool(PreferenceKeys.RouteOverridesEnabled.key, false)
set(value) { mmkv.encode(PreferenceKeys.RouteOverridesEnabled.key, value) }
override var routeOverrides: Set<String>
get() = mmkv.decodeStringSet(PreferenceKeys.RouteOverrides.key, emptySet<String>())!!.toSet()
set(value) { mmkv.encode(PreferenceKeys.RouteOverrides.key, value) }
override fun reset() {
mmkv.removeValuesForKeys(mmkv.allKeys())
}
private fun asState(): PreferencesState {
return PreferencesState(
managementUrl = managementUrl,
ssoSupported = ssoSupported,
hasAuthed = hasAuthed,
preSharedKey = preSharedKey,
setupKey = setupKey,
rosenpass = rosenpass,
rosenpassPermissive = rosenpassPermissive,
engineLogging = engineLogging,
verboseEngineLogging = verboseEngineLogging,
liveEngineLogging = liveEngineLogging,
logging = logging,
verboseLogging = verboseLogging,
excludedApps = excludedApps,
routeOverridesEnabled = routeOverridesEnabled,
routeOverrides = routeOverrides
)
}
}
data class PreferencesState(
// NetBird
override var managementUrl: String?,
override var ssoSupported: Boolean,
override var hasAuthed: Boolean,
override var preSharedKey: String?,
override var setupKey: String?,
override var rosenpass: Boolean,
override var rosenpassPermissive: Boolean,
override var engineLogging: Boolean,
override var verboseEngineLogging: Boolean,
override var liveEngineLogging: Boolean,
// JetBird
override var logging: Boolean,
override var verboseLogging: Boolean,
override var excludedApps: Set<String>,
override var routeOverridesEnabled: Boolean,
override var routeOverrides: Set<String>
): PreferencesValues
private enum class PreferenceKeys(
val key: String
) {
ID("preferences"),
// NetBird
ManagementUrl("management_url"),
SsoSupported("sso_supported"),
HasAuthed("has_authed"),
PreSharedKey("pre_shared_key"),
SetupKey("setup_key"),
Rosenpass("rosenpass"),
RosenpassPermissive("rosenpass_permissive"),
EngineLogging("engine_logging"),
VerboseEngineLogging("verbose_engine_logging"),
LiveEngineLogging("live_engine_logging"),
// JetBird
Logging("logging"),
VerboseLogging("verbose_logging"),
ExcludedApps("excluded_apps"),
RouteOverridesEnabled("route_overrides_enabled"),
RouteOverrides("route_overrides")
}

View File

@@ -0,0 +1,18 @@
package dev.bg.jetbird.repository
import javax.inject.Inject
interface VpnRepository {
fun isVpnConnected(): Boolean
fun updateVpnState(connected: Boolean)
}
class VpnRepositoryImpl @Inject constructor(): VpnRepository {
private var _isVpnConnected = false
override fun isVpnConnected() = _isVpnConnected
override fun updateVpnState(connected: Boolean) {
_isVpnConnected = connected
}
}

View File

@@ -0,0 +1,91 @@
package dev.bg.jetbird.service
import android.content.Intent
import android.net.VpnService
import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import android.widget.Toast
import dagger.hilt.android.AndroidEntryPoint
import dev.bg.jetbird.R
import dev.bg.jetbird.data.Actions
import dev.bg.jetbird.repository.VpnRepository
import dev.bg.jetbird.util.IoDispatcher
import dev.bg.jetbird.util.ReplaceableJob
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import javax.inject.Inject
@AndroidEntryPoint
class Tile: TileService() {
@Inject
lateinit var vpnRepository: VpnRepository
@Inject
@IoDispatcher
lateinit var ioDispatcher: CoroutineDispatcher
private lateinit var scope: CoroutineScope
private var job = ReplaceableJob()
override fun onCreate() {
super.onCreate()
scope = CoroutineScope(ioDispatcher)
}
override fun onStartListening() {
super.onStartListening()
startUpdateJob()
}
override fun onStopListening() {
job.cancel()
super.onStopListening()
}
override fun onDestroy() {
job.cancel()
super.onDestroy()
}
override fun onClick() {
if (VpnService.prepare(this) == null) {
if (vpnRepository.isVpnConnected()) {
startService(
Intent(this, VPNService::class.java).apply {
action = Actions.TILE_STOP_SERVICE_ACTION
}
)
} else {
startService(
Intent(this, VPNService::class.java).apply {
action = Actions.TILE_START_SERVICE_ACTION
}
)
}
} else {
Toast.makeText(this, getString(R.string.requires_vpn_permission), Toast.LENGTH_LONG).show()
}
}
private fun startUpdateJob() {
job += scope.launch {
while (isActive) {
updateTile(vpnRepository.isVpnConnected())
delay(2000L)
}
}
}
private fun updateTile(
isActive: Boolean
) {
val tile = qsTile ?: return
tile.state = if (isActive) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
tile.updateTile()
}
}

View File

@@ -0,0 +1,388 @@
package dev.bg.jetbird.service
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Intent
import android.net.VpnService
import android.os.Binder
import android.os.Build
import android.os.IBinder
import android.os.Parcel
import androidx.core.app.NotificationCompat
import dagger.hilt.android.AndroidEntryPoint
import dev.bg.jetbird.R
import dev.bg.jetbird.data.Actions
import dev.bg.jetbird.data.NetBirdErrors
import dev.bg.jetbird.data.model.ConnectionState
import dev.bg.jetbird.data.model.Peer
import dev.bg.jetbird.data.model.ServiceEvent
import dev.bg.jetbird.data.model.VPNState
import dev.bg.jetbird.lib.EngineLoggingLevel
import dev.bg.jetbird.lib.Tunnel
import dev.bg.jetbird.lib.TunnelListener
import dev.bg.jetbird.repository.LogRepository
import dev.bg.jetbird.repository.PreferencesRepository
import dev.bg.jetbird.repository.VpnRepository
import dev.bg.jetbird.util.IoDispatcher
import dev.bg.jetbird.util.Log
import dev.bg.jetbird.util.ReplaceableJob
import dev.bg.jetbird.util.ktx.toPeerList
import io.netbird.android.ConnectionListener
import io.netbird.android.URLOpener
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.delay
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
@AndroidEntryPoint
class VPNService: VpnService() {
@Inject
lateinit var logRepository: LogRepository
@Inject
lateinit var preferencesRepository: PreferencesRepository
@Inject
lateinit var vpnRepository: VpnRepository
@Inject
@IoDispatcher
lateinit var ioDispatcher: CoroutineDispatcher
private val scope = CoroutineScope(SupervisorJob())
private val _state: MutableStateFlow<VPNState> = MutableStateFlow(
VPNState(
connectionState = ConnectionState.DISCONNECTED,
peers = emptyList()
)
)
private val _events = MutableSharedFlow<ServiceEvent>()
private var tunnel: Tunnel? = null
private var isTunnelStarted = false
private var hasAuthed = false
// Logging
private var engineLoggingLevel = EngineLoggingLevel.None
private var isLiveLoggingEnabled = false
private lateinit var liveLoggingScope: CoroutineScope
private var liveLoggingJob = ReplaceableJob()
private var isLoggingEnabled = false
private var isVerboseLoggingEnabled = false
override fun onCreate() {
super.onCreate()
liveLoggingScope = CoroutineScope(ioDispatcher)
tunnel = Tunnel(this, serviceStateListener, connectionListener)
hasAuthed = preferencesRepository.hasAuthed
isLoggingEnabled = preferencesRepository.logging
isVerboseLoggingEnabled = preferencesRepository.verboseLogging
setEngineLoggingLevel(preferencesRepository.engineLogging, preferencesRepository.verboseEngineLogging)
scope.launch {
preferencesRepository.state.collectLatest {
hasAuthed = it.hasAuthed
isLoggingEnabled = it.logging
isVerboseLoggingEnabled = it.verboseLogging
setEngineLoggingLevel(it.engineLogging, it.verboseEngineLogging)
isLiveLoggingEnabled = it.liveEngineLogging
if (it.liveEngineLogging) {
startEngineLogTailing()
} else {
if (liveLoggingJob.isActive) {
liveLoggingJob.cancel()
}
}
}
}
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (intent == null) {
return START_NOT_STICKY
}
if (intent.action == Actions.TILE_STOP_SERVICE_ACTION && isTunnelStarted) {
stop()
}
if (intent.action == Actions.TILE_START_SERVICE_ACTION && !isTunnelStarted && hasAuthed) {
log("Starting tunnel from quick tile")
startInForeground()
start(null)
}
if (intent.action == Actions.ALWAYS_ON_START && hasAuthed) {
log("Android requesting us to start through always-on VPN", force = true)
startInForeground()
start(null)
}
return super.onStartCommand(intent, flags, startId)
}
override fun onBind(intent: Intent): IBinder {
log("onBind()", verbose = true)
return VPNServiceBinder()
}
override fun onUnbind(intent: Intent): Boolean {
log("onUnbind()", verbose = true)
if (!isTunnelStarted) {
stopSelf()
}
return false
}
override fun onDestroy() {
log("onDestroy()", verbose = true)
super.onDestroy()
stop()
}
override fun onRevoke() {
log("onRevoke()", verbose = true)
stop()
if (isLiveLoggingEnabled && liveLoggingJob.isActive) {
scope.launch {
liveLoggingJob.cancel()
}
}
}
private fun start(urlOpener: URLOpener?) {
log("Starting NetBird", verbose = true)
startInForeground()
if (isLiveLoggingEnabled) {
startEngineLogTailing()
}
tunnel?.start(
urlOpener = urlOpener,
loggingLevel = engineLoggingLevel,
excludeApps = preferencesRepository.excludedApps,
enableRouteOverrides = preferencesRepository.routeOverridesEnabled,
overrides = preferencesRepository.routeOverrides
)
}
private fun stop() {
log("Requested disconnect")
if (liveLoggingJob.isActive) {
scope.launch {
liveLoggingJob.cancel()
}
}
tunnel?.stop()
stopForeground(STOP_FOREGROUND_REMOVE)
}
val tunnelBuilder: Builder
get() = Builder()
val isUsingPrivateDns: Boolean
get() = tunnel?.dnsWatch?.isPrivateDnsActive ?: false
inner class VPNServiceBinder: Binder() {
val state: StateFlow<VPNState>
get() = _state.asStateFlow()
val events: SharedFlow<ServiceEvent>
get() = _events.asSharedFlow()
fun start(urlOpener: URLOpener?) {
this@VPNService.start(urlOpener)
}
fun stop() {
log("Stopping NetBird", verbose = true)
tunnel?.stop()
}
fun getState() = _state.value
fun getPeers(): List<Peer>? {
return tunnel
?.peersInfo()
?.toPeerList()
?.sortedBy { peer -> peer.fqdn }
}
// These are broken
// Can't start listener without making Netbird unfunctional - needs issue
// fun startClientListener() {
// tunnel?.startClientListener()
// }
//
// fun stopClientListener() {
// tunnel?.stopClientListener()
// }
override fun onTransact(code: Int, data: Parcel, reply: Parcel?, flags: Int): Boolean {
if (code == LAST_CALL_TRANSACTION) {
onRevoke()
return true
}
return false
}
}
private fun startInForeground() {
log("Starting in foreground", verbose = true)
val channelId = getString(R.string.app_name)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
(getSystemService(NOTIFICATION_SERVICE) as NotificationManager).createNotificationChannel(
NotificationChannel(
channelId,
getString(R.string.app_name),
NotificationManager.IMPORTANCE_DEFAULT
)
)
}
val notification = NotificationCompat.Builder(application, channelId)
.setSmallIcon(R.drawable.ic_stat)
.setContentTitle(this.getString(R.string.app_name))
.setContentText(this.getString(R.string.foreground_notification_description))
.build()
startForeground(1, notification)
}
// THIS IS NOT IN USE
private var connectionListener = object : ConnectionListener {
override fun onConnecting() {
Timber.d("Netbird connecting")
_state.update { it.copy(connectionState = ConnectionState.CONNECTING) }
}
override fun onConnected() {
Timber.d("Netbird connected")
_state.update { it.copy(connectionState = ConnectionState.CONNECTED) }
}
override fun onAddressChanged(fqdn: String, address: String) {
Timber.d("Netbird address changed - fqdn: $fqdn address: $address")
}
override fun onPeersListChanged(numberOfPeers: Long) {
Timber.d("Netbird peers changed: $numberOfPeers")
_state.update { it.copy(peers = tunnel?.peersInfo().toPeerList()) }
}
override fun onDisconnecting() {
Timber.d("Netbird disconnecting")
_state.update { it.copy(connectionState = ConnectionState.DISCONNECTING) }
}
override fun onDisconnected() {
Timber.d("Netbird disconnected")
_state.update { it.copy(connectionState = ConnectionState.DISCONNECTED) }
}
}
private fun log(
message: String,
verbose: Boolean = false,
force: Boolean = false
) {
Timber.d(message)
if (force) {
return logRepository.log(message)
}
if (isVerboseLoggingEnabled || (isLoggingEnabled && !verbose)) {
logRepository.log(message)
}
}
private fun engineLog(
message: String
) {
logRepository.log(Log.getLogcatLineContent(message))
}
private fun setEngineLoggingLevel(
logging: Boolean,
verboseLogging: Boolean
) {
engineLoggingLevel = when {
logging && verboseLogging -> EngineLoggingLevel.Trace
logging -> EngineLoggingLevel.Info
else -> EngineLoggingLevel.None
}
}
private fun startEngineLogTailing() {
liveLoggingJob += liveLoggingScope.launch {
Runtime.getRuntime().exec("logcat -c")
Runtime.getRuntime().exec("logcat -s GoLog")
.inputStream
.bufferedReader()
.useLines {
it.forEach { l ->
ensureActive()
engineLog(l)
}
}
}
}
private fun reduceTunnelFailure(
failure: String
) {
when {
NetBirdErrors.all.contains(failure) -> {
log("NetBird auth error: $failure", force = true)
scope.launch {
_events.emit(ServiceEvent(failure))
}
}
else -> log("Tunnel failure: $failure", force = true)
}
}
private var serviceStateListener = object : TunnelListener {
override fun onStarted() {
isTunnelStarted = true
vpnRepository.updateVpnState(true)
log("Tunnel setup complete", verbose = true)
_state.update { it.copy(connectionState = ConnectionState.CONNECTED) }
}
override fun onStopped() {
isTunnelStarted = false
vpnRepository.updateVpnState(false)
log("Tunnel stopped", verbose = true)
_state.update { it.copy(connectionState = ConnectionState.DISCONNECTED) }
stop()
}
override fun onRequiresRestart() {
stop()
scope.launch {
delay(5000L)
start(null)
}
}
override fun onLog(
message: String,
verbose: Boolean,
force: Boolean
) {
log(message, verbose, force)
}
override fun onError(message: String) {
isTunnelStarted = false
vpnRepository.updateVpnState(false)
reduceTunnelFailure(message)
_state.update { it.copy(connectionState = ConnectionState.DISCONNECTED) }
stop()
}
}
}

View File

@@ -0,0 +1,163 @@
package dev.bg.jetbird.ui
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.currentBackStackEntryAsState
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.bg.jetbird.LocalNavController
import dev.bg.jetbird.LocalSnackbar
import dev.bg.jetbird.LocalVPNServiceBinder
import dev.bg.jetbird.R
import dev.bg.jetbird.Route
import dev.bg.jetbird.ScaffoldVisibility
import dev.bg.jetbird.data.NetBirdErrors
import dev.bg.jetbird.repository.PreferencesRepository
import dev.bg.jetbird.ui.screens.credits.CreditsScreen
import dev.bg.jetbird.ui.screens.home.HomeScreen
import dev.bg.jetbird.ui.screens.log.LogScreen
import dev.bg.jetbird.ui.screens.routeselector.RouteSelectorScreen
import dev.bg.jetbird.ui.screens.settings.SettingsScreen
import dev.bg.jetbird.ui.screens.setup.SetupScreen
import dev.bg.jetbird.util.IoDispatcher
import dev.bg.jetbird.util.ktx.composable
import dev.bg.jetbird.util.ktx.navigate
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import javax.inject.Inject
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Navigation(
viewModel: NavigationViewModel = hiltViewModel()
) {
val ctx = LocalContext.current
val navController = LocalNavController.current
val snackbarHostState = LocalSnackbar.current
val binder = LocalVPNServiceBinder.current
val backStack by navController.currentBackStackEntryAsState()
val scaffoldVisibility = Route.getScaffoldVisibility(backStack?.destination?.route)
LaunchedEffect(binder) {
binder?.events?.collectLatest { event ->
val message = when (event.event) {
NetBirdErrors.NETBIRD_TUNNEL_FAILURE -> {
viewModel.resetAuthState()
ctx.getString(R.string.auth_error_see_logs)
}
else -> ctx.getString(R.string.unknown_error_see_logs)
}
snackbarHostState.showSnackbar(message)
}
}
Scaffold(
topBar = {
TopAppBar(
title = {},
navigationIcon = {
AnimatedVisibility(
scaffoldVisibility == ScaffoldVisibility.Top ||
scaffoldVisibility == ScaffoldVisibility.NavOnly
) {
IconButton(
onClick = {
navController.navigateUp()
}
) {
Icon(
Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = null
)
}
}
},
actions = {
AnimatedVisibility(
scaffoldVisibility == ScaffoldVisibility.Top ||
scaffoldVisibility == ScaffoldVisibility.ActionsOnly
) {
Row {
IconButton(onClick = { navController.navigate(Route.Log) }) {
Icon(
painterResource(R.drawable.baseline_list_24),
contentDescription = stringResource(R.string.log)
)
}
IconButton(onClick = { navController.navigate(Route.Settings) }) {
Icon(
Icons.Filled.Settings,
contentDescription = stringResource(R.string.settings)
)
}
}
}
}
)
},
snackbarHost = { SnackbarHost(snackbarHostState) },
bottomBar = {}
) { padding ->
NavHost(
navController,
if (viewModel.needsSetup()) Route.Setup.route else Route.Home.route,
Modifier.padding(padding)
) {
composable(Route.Home) {
HomeScreen()
}
composable(Route.Setup) {
SetupScreen()
}
composable(Route.Log) {
LogScreen()
}
composable(Route.Settings) {
SettingsScreen()
}
composable(Route.RouteSelector) {
RouteSelectorScreen()
}
composable(Route.Credits) {
CreditsScreen()
}
}
}
}
@HiltViewModel
class NavigationViewModel @Inject constructor(
private val preferencesRepository: PreferencesRepository,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher
): ViewModel() {
fun needsSetup() = preferencesRepository.managementUrl == null
fun resetAuthState() {
viewModelScope.launch(ioDispatcher) {
preferencesRepository.hasAuthed = false
preferencesRepository.updateState()
}
}
}

View File

@@ -0,0 +1,104 @@
package dev.bg.jetbird.ui.components
import android.os.SystemClock
import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import dev.bg.jetbird.R
import dev.bg.jetbird.data.JetBirdColors
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlin.math.ceil
import androidx.compose.ui.graphics.Color as ComposeColor
@Composable
fun DeleteAlertDialog(
title: String,
description: String,
open: Boolean,
onDismissRequest: () -> Unit,
onDelete: () -> Unit
) {
if (open) {
AlertDialog(
onDismissRequest = onDismissRequest,
title = {
Text(title)
},
text = {
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text(description)
Text(
stringResource(R.string.action_not_reversible),
fontWeight = FontWeight.SemiBold
)
}
},
dismissButton = {
OutlinedButton(onClick = onDismissRequest) {
Text(stringResource(R.string.cancel))
}
},
confirmButton = {
CountdownDeleteButton(onDelete = onDelete)
}
)
}
}
@Composable
private fun CountdownDeleteButton(
onDelete: () -> Unit
) {
val waitTime = 3000
var remaining by remember { mutableIntStateOf(waitTime) }
var ready by remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
val start = SystemClock.uptimeMillis()
while (isActive && remaining > 0) {
remaining = (waitTime - ((SystemClock.uptimeMillis() - start).coerceAtLeast(0L))).coerceAtLeast(0L).toInt()
if (remaining == 0) {
ready = true
}
delay(200.coerceAtMost(remaining).toLong())
}
}
Button(
enabled = remaining == 0,
colors = ButtonDefaults.buttonColors(
containerColor = JetBirdColors.ErrorRed,
contentColor = ComposeColor.White
),
onClick = onDelete
) {
AnimatedContent(ready, label = "") {
when (it) {
true -> {
Text(stringResource(R.string.delete))
}
false -> {
Text(ceil(remaining.toDouble() / 1000).toInt().toString())
}
}
}
}
}

View File

@@ -0,0 +1,66 @@
package dev.bg.jetbird.ui.components
import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonColors
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.ButtonElevation
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ProgressIndicatorDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.unit.dp
@Composable
fun LoadingButton(
onClick: () -> Unit,
loading: Boolean,
modifier: Modifier = Modifier,
enabled: Boolean = true,
shape: Shape = ButtonDefaults.shape,
colors: ButtonColors = ButtonDefaults.buttonColors(),
elevation: ButtonElevation? = ButtonDefaults.buttonElevation(),
border: BorderStroke? = null,
contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
content: @Composable () -> Unit
) {
Button(
onClick = {
if (!loading) {
onClick()
}
},
modifier,
enabled = !loading && enabled,
shape,
colors,
elevation,
border,
contentPadding,
interactionSource,
) {
AnimatedContent(
loading,
label = "Loading button animation"
) { internalState ->
when (internalState) {
true -> {
CircularProgressIndicator(
modifier = Modifier.size(24.dp),
strokeWidth = ProgressIndicatorDefaults.CircularStrokeWidth * 0.75f
)
}
false -> {
content()
}
}
}
}
}

View File

@@ -0,0 +1,156 @@
package dev.bg.jetbird.ui.components
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import dev.bg.jetbird.LocalLayoutType
import dev.bg.jetbird.data.LayoutType
import dev.bg.jetbird.util.ktx.conditional
@Composable
fun SettingsSection(
title: String,
content: @Composable () -> Unit
) {
Column(
Modifier
.fillMaxWidth()
.padding(vertical = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Text(
title,
color = MaterialTheme.colorScheme.primary
)
content()
}
}
@Composable
fun SettingsTile(
title: String,
description: String,
onClick: (() -> Unit)? = null
) {
Column(
Modifier
.fillMaxWidth()
.conditional(onClick != null) {
clickable {
onClick!!.invoke()
}
}
) {
Text(title)
Text(
description,
color = MaterialTheme.colorScheme.secondary
)
}
}
@Composable
fun SettingsTileWithValue(
title: String,
description: String? = null,
value: String,
onClick: (() -> Unit)? = null
) {
val layoutType = LocalLayoutType.current
Row(
Modifier
.fillMaxWidth()
.conditional(onClick != null) {
clickable {
onClick!!()
}
},
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
if (description == null) {
Text(
title,
modifier = Modifier.padding(vertical = 4.dp)
)
} else {
Column {
Text(title)
Text(
description,
color = MaterialTheme.colorScheme.secondary
)
}
}
Text(
when {
layoutType != LayoutType.CompactPortrait -> value
value.length > 15 -> "${value.take(8)}...${value.takeLast(8)}"
else -> value
},
color = MaterialTheme.colorScheme.secondary
)
}
}
@Composable
fun SettingsSwitch(
title: String,
description: String? = null,
checked: Boolean,
onChange: (Boolean) -> Unit
) {
Row(
Modifier
.fillMaxWidth()
.clickable {
onChange(!checked)
},
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
if (description == null) {
Text(title)
} else {
Column(Modifier.weight(1f)) {
Text(title)
Text(
description,
color = MaterialTheme.colorScheme.secondary
)
}
}
Switch(
checked = checked,
onCheckedChange = onChange,
thumbContent = if (checked) {
{
Icon(
Icons.Filled.Check,
contentDescription = null,
modifier = Modifier.size(SwitchDefaults.IconSize)
)
}
} else null,
modifier = Modifier
.padding(horizontal = 4.dp)
.padding(start = 12.dp)
)
}
}

View File

@@ -0,0 +1,81 @@
package dev.bg.jetbird.ui.components
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Done
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.SwipeToDismissBox
import androidx.compose.material3.SwipeToDismissBoxValue
import androidx.compose.material3.rememberSwipeToDismissBoxState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.unit.dp
import dev.bg.jetbird.data.JetBirdColors
@Composable
@OptIn(ExperimentalMaterial3Api::class)
fun SwipeToDelete(
modifier: Modifier,
onDeleted: () -> Unit,
content: @Composable () -> Unit
) {
val dismissState = rememberSwipeToDismissBoxState(
confirmValueChange = {
if (it == SwipeToDismissBoxValue.EndToStart) {
onDeleted()
true
} else false
}
)
SwipeToDismissBox(
state = dismissState,
backgroundContent = {
val dir = dismissState.dismissDirection
val color by animateColorAsState(
JetBirdColors.ErrorRed.copy(alpha = (dismissState.progress * 2).coerceAtMost(1f)),
label = ""
)
val scale by animateFloatAsState(
(0.5f + (dismissState.progress * 2)).coerceAtMost(1f),
label = ""
)
Box(
Modifier
.fillMaxSize()
.background(color, CardDefaults.elevatedShape)
.padding(horizontal = 20.dp),
contentAlignment = when (dir) {
SwipeToDismissBoxValue.StartToEnd -> Alignment.CenterStart
else -> Alignment.CenterEnd
}
) {
Icon(
when (dir) {
SwipeToDismissBoxValue.StartToEnd -> Icons.Default.Done
else -> Icons.Default.Delete
},
contentDescription = null,
modifier = Modifier.scale(scale)
)
}
},
modifier = modifier,
enableDismissFromStartToEnd = false,
enableDismissFromEndToStart = true
) {
content()
}
}

View File

@@ -0,0 +1,19 @@
package dev.bg.jetbird.ui.components
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.style.TextAlign
@Composable
fun MonospaceText(
text: String,
textAlign: TextAlign? = null,
) {
Text(
text = text,
textAlign = textAlign,
style = MaterialTheme.typography.bodyMedium.copy(fontFamily = FontFamily.Monospace)
)
}

View File

@@ -0,0 +1,108 @@
package dev.bg.jetbird.ui.components
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import dev.bg.jetbird.R
@Composable
fun TextFieldAlertDialog(
open: Boolean,
title: String,
label: String,
enabled: Boolean = true,
initialValue: String? = "",
supportingText: String? = null,
placeholder: String? = null,
inputType: OutlinedTextFieldInputType,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
onDismissRequest: () -> Unit,
onEntered: (String?) -> Unit
) {
var input by remember { mutableStateOf(initialValue ?: "") }
fun dismiss() {
if (initialValue != null) {
input = initialValue
}
onDismissRequest()
}
if (open) {
AlertDialog(
title = {
Text(title)
},
text = {
Column {
TypedOutlinedTextField(
value = input,
onValueChange = {
input = it
},
label = { Text(label) },
placeholder = { if (placeholder != null) { Text(placeholder) } },
inputType = inputType,
keyboardOptions = keyboardOptions,
maxLines = 1,
enabled = enabled
)
if (supportingText != null) {
Spacer(Modifier.height(4.dp))
Text(supportingText)
}
}
},
onDismissRequest = onDismissRequest,
dismissButton = {
if (enabled) {
OutlinedButton(
onClick = {
dismiss()
}
) {
Text(stringResource(R.string.cancel))
}
}
},
confirmButton = {
Button(
onClick = {
if (!enabled) {
dismiss()
return@Button
}
if (input.isEmpty()) {
onEntered(null)
input = ""
dismiss()
} else {
onEntered(input)
input = ""
dismiss()
}
}
) {
if (enabled) {
Text(stringResource(R.string.confirm))
} else {
Text(stringResource(R.string.close))
}
}
}
)
}
}

View File

@@ -0,0 +1,89 @@
package dev.bg.jetbird.ui.components
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.TextFieldColors
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.VisualTransformation
enum class OutlinedTextFieldInputType {
Alphabet,
Alphanumeric,
Numeric,
Any
}
@Composable
fun TypedOutlinedTextField(
value: String,
onValueChange: (String) -> Unit,
inputType: OutlinedTextFieldInputType,
modifier: Modifier = Modifier,
enabled: Boolean = true,
readOnly: Boolean = false,
textStyle: TextStyle = LocalTextStyle.current,
label: @Composable (() -> Unit)? = null,
placeholder: @Composable (() -> Unit)? = null,
leadingIcon: @Composable (() -> Unit)? = null,
trailingIcon: @Composable (() -> Unit)? = null,
prefix: @Composable (() -> Unit)? = null,
suffix: @Composable (() -> Unit)? = null,
supportingText: @Composable (() -> Unit)? = null,
isError: Boolean = false,
visualTransformation: VisualTransformation = VisualTransformation.None,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
singleLine: Boolean = false,
maxLines: Int = if (singleLine) 1 else Int.MAX_VALUE,
minLines: Int = 1,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
shape: Shape = OutlinedTextFieldDefaults.shape,
colors: TextFieldColors = OutlinedTextFieldDefaults.colors()
) {
val pattern = remember {
when (inputType) {
OutlinedTextFieldInputType.Alphabet -> Regex("[a-zA-z\\s]*")
OutlinedTextFieldInputType.Alphanumeric -> Regex("[a-zA-z0-9\\s]*")
OutlinedTextFieldInputType.Numeric -> Regex("^\\d+\$")
OutlinedTextFieldInputType.Any -> Regex(".*")
}
}
OutlinedTextField(
value = value,
onValueChange = {
if (it.isEmpty() || it.matches(pattern)) {
onValueChange(it)
}
},
modifier = modifier,
enabled = enabled,
readOnly = readOnly,
textStyle = textStyle,
label = label,
placeholder = placeholder,
leadingIcon = leadingIcon,
trailingIcon = trailingIcon,
prefix = prefix,
suffix = suffix,
supportingText = supportingText,
isError = isError,
visualTransformation = visualTransformation,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
singleLine = singleLine,
maxLines = maxLines,
minLines = minLines,
interactionSource = interactionSource,
shape = shape,
colors = colors
)
}

View File

@@ -0,0 +1,93 @@
package dev.bg.jetbird.ui.screens.credits
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import dev.bg.jetbird.R
const val GPL_V2 = "GNU General Public License v2.0"
const val APACHE_V2 = "Apache License, Version 2.0"
const val MIT = "MIT License"
const val BSD = "BSD 3-Clause License"
@Composable
fun CreditsScreen() {
val libraries = listOf(
Library("Kotlin", APACHE_V2, "https://kotlinlang.org"),
Library("AndroidX / Jetpack", APACHE_V2, "https://github.com/androidx/androidx"),
Library("Desugar JDK", GPL_V2, "https://github.com/google/desugar_jdk_libs"),
Library("NetBird", BSD, "https://github.com/netbirdio/netbird"),
Library("Dagger", APACHE_V2, "https://dagger.dev"),
Library("MMKV", BSD, "https://github.com/Tencent/MMKV"),
Library("Timber", APACHE_V2, "https://github.com/JakeWharton/timber"),
Library("LeakCanary", APACHE_V2, "https://square.github.io/leakcanary"),
Library("IPAddress", APACHE_V2, "https://github.com/seancfoley/IPAddress")
)
LazyColumn(
Modifier
.fillMaxSize()
.padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
item {
Text(
stringResource(R.string.credits),
fontSize = 36.sp,
fontWeight = FontWeight.W400
)
Spacer(Modifier.size(16.dp))
}
itemsIndexed(libraries) { idx, library ->
LibraryItem(library)
Spacer(Modifier.size(8.dp))
if (idx != libraries.size - 1) {
HorizontalDivider()
}
}
}
}
@Composable
private fun LibraryItem(
library: Library
) {
val uriHandler = LocalUriHandler.current
Column(
Modifier
.fillMaxWidth()
.clickable {
uriHandler.openUri(library.url)
}
) {
Text(library.title)
Text(
library.license,
color = MaterialTheme.colorScheme.secondary
)
}
}
private data class Library(
val title: String,
val license: String,
val url: String
)

View File

@@ -0,0 +1,430 @@
package dev.bg.jetbird.ui.screens.home
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.VpnService
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.BottomSheetScaffold
import androidx.compose.material3.Button
import androidx.compose.material3.Card
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.SheetValue
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.rememberBottomSheetScaffoldState
import androidx.compose.material3.rememberStandardBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.bg.jetbird.LocalServiceConnection
import dev.bg.jetbird.LocalSnackbar
import dev.bg.jetbird.LocalVPNServiceBinder
import dev.bg.jetbird.R
import dev.bg.jetbird.data.JetBirdColors
import dev.bg.jetbird.data.model.ConnectionState
import dev.bg.jetbird.data.model.Peer
import dev.bg.jetbird.service.VPNService
import dev.bg.jetbird.util.OnLifecycleEvent
import dev.bg.jetbird.util.ktx.hasOtherAlwaysOnVpn
import io.netbird.android.URLOpener
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlin.time.Duration.Companion.seconds
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen(
viewModel: HomeViewModel = hiltViewModel()
) {
val ctx = LocalContext.current
val binder = LocalVPNServiceBinder.current
val serviceConnection = LocalServiceConnection.current
val uriHandler = LocalUriHandler.current
val snackbar = LocalSnackbar.current
val scope = rememberCoroutineScope()
val vpnState = binder?.state?.collectAsStateWithLifecycle()?.value
var hasOtherAlwaysOnVpn by remember { mutableStateOf(false) }
var hasVpnPermission by remember { mutableStateOf(false) }
val vpnPermissionLauncher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
when (result.resultCode) {
Activity.RESULT_OK -> {
hasVpnPermission = true
}
Activity.RESULT_CANCELED -> {
scope.launch {
snackbar.showSnackbar(ctx.getString(R.string.failed_vpn_permission))
}
}
}
}
OnLifecycleEvent { _, event ->
when (event) {
Lifecycle.Event.ON_START,
Lifecycle.Event.ON_RESUME -> {
hasOtherAlwaysOnVpn = vpnState?.connectionState != ConnectionState.CONNECTED && ctx.hasOtherAlwaysOnVpn()
hasVpnPermission = VpnService.prepare(ctx) == null
if (!hasOtherAlwaysOnVpn && hasVpnPermission && binder == null) {
val i = Intent(ctx, VPNService::class.java)
ctx.startService(i)
ctx.bindService(i, serviceConnection, Context.BIND_AUTO_CREATE)
}
}
else -> Unit
}
}
val loginListener = URLOpener { url -> uriHandler.openUri(url) }
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
val peerListState = rememberLazyListState()
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberStandardBottomSheetState(
confirmValueChange = {
if (it == SheetValue.PartiallyExpanded) {
scope.launch {
peerListState.animateScrollToItem(0)
}
}
true
}
)
)
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetShape = RoundedCornerShape(
bottomStart = 0.dp,
bottomEnd = 0.dp,
topStart = 12.dp,
topEnd = 12.dp
),
sheetShadowElevation = 8.dp,
sheetTonalElevation = 8.dp,
sheetContent = {
PeersList(peerListState)
},
sheetPeekHeight = 96.dp
) { padding ->
Box(
Modifier
.fillMaxSize()
.padding(padding)
) {
AlwaysOnVpnBanner(
isNetbirdRunning = binder != null && vpnState?.connectionState != ConnectionState.DISCONNECTED,
hasOtherAlwaysOnVpn = hasOtherAlwaysOnVpn,
modifier = Modifier.align(Alignment.TopCenter)
)
when {
hasVpnPermission && (vpnState?.connectionState == ConnectionState.CONNECTED || vpnState?.connectionState == ConnectionState.DISCONNECTED) -> {
Column(
Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(
modifier = Modifier.size(256.dp),
shape = RoundedCornerShape(16.dp),
enabled = !hasOtherAlwaysOnVpn,
onClick = {
if (vpnState.connectionState == ConnectionState.DISCONNECTED) {
if (viewModel.hasAuthed()) {
binder.start(null)
} else {
if (viewModel.getSetupKey() == null) {
binder.start(loginListener)
} else {
binder.start(null)
}
viewModel.updateHasAuthed()
}
} else {
binder.stop()
}
}
) {
Icon(
painterResource(R.drawable.ic_launcher_monochrome),
modifier = Modifier.fillMaxSize(),
contentDescription = if (vpnState.connectionState == ConnectionState.CONNECTED) {
stringResource(R.string.connected)
} else {
stringResource(R.string.disconnect)
}
)
}
Spacer(Modifier.size(36.dp))
AnimatedContent(
vpnState.connectionState,
label = "Connection state animation"
) {connectionState ->
if (connectionState == ConnectionState.CONNECTED) {
Text(
text = stringResource(R.string.connected),
fontWeight = FontWeight.SemiBold,
fontSize = 24.sp
)
} else {
Text(
text = stringResource(R.string.disconnected),
fontWeight = FontWeight.SemiBold,
fontSize = 24.sp
)
}
}
}
}
hasVpnPermission && (vpnState?.connectionState == ConnectionState.CONNECTING || vpnState?.connectionState == ConnectionState.DISCONNECTING) -> {
CircularProgressIndicator()
}
!hasVpnPermission -> {
Column(
Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
stringResource(R.string.requires_vpn_permission),
textAlign = TextAlign.Center
)
Spacer(Modifier.height(16.dp))
Button(
enabled = !hasOtherAlwaysOnVpn,
onClick = {
vpnPermissionLauncher.launch(VpnService.prepare(ctx))
}
) {
Text(stringResource(R.string.grant_permission))
}
}
}
}
}
}
}
}
@Composable
private fun AlwaysOnVpnBanner(
isNetbirdRunning: Boolean,
hasOtherAlwaysOnVpn: Boolean,
modifier: Modifier
) {
if (!isNetbirdRunning && hasOtherAlwaysOnVpn) {
Surface(
Modifier
.fillMaxWidth()
.padding(8.dp)
.clip(RoundedCornerShape(12.dp))
.then(modifier),
color = JetBirdColors.ErrorRed
) {
Text(
stringResource(R.string.another_always_on_vpn_active),
textAlign = TextAlign.Center,
modifier = Modifier.padding(vertical = 6.dp)
)
}
}
}
@OptIn(ExperimentalFoundationApi::class)
@Composable
private fun PeersList(
lazyListState: LazyListState
) {
val binder = LocalVPNServiceBinder.current
val connectionState = binder?.state?.collectAsStateWithLifecycle()?.value?.connectionState
var selectedPeerIp by remember { mutableStateOf<String?>(null) }
var peers by remember { mutableStateOf<List<Peer>>(emptyList()) }
// temporary whilst listener gets fixed
LaunchedEffect(Unit, connectionState) {
while (true) {
if (connectionState == ConnectionState.CONNECTED) {
val newPeers = binder.getPeers() ?: emptyList()
if (peers != newPeers) {
peers = newPeers
}
}
if (connectionState == ConnectionState.DISCONNECTED) {
peers = emptyList()
}
delay(5.seconds)
}
}
LazyColumn(
state = lazyListState,
modifier = Modifier
.fillMaxSize()
.padding(bottom = 12.dp),
verticalArrangement = Arrangement.spacedBy(12.dp),
horizontalAlignment = Alignment.CenterHorizontally,
userScrollEnabled = connectionState != null && connectionState == ConnectionState.CONNECTED
) {
item {
Text(
stringResource(R.string.peers_connected,
peers.filter { it.connectionStatus == "Connected" }.size,
peers.size
)
)
Spacer(Modifier.size(16.dp))
}
if (peers.isEmpty()) {
item {
Box(
Modifier.fillParentMaxSize(0.95f),
contentAlignment = Alignment.Center
) {
if (connectionState == null || connectionState == ConnectionState.DISCONNECTED) {
Text(stringResource(R.string.connect_to_see_peers))
} else {
CircularProgressIndicator()
}
}
}
}
items(
peers,
key = { peer -> peer.ip.ifEmpty { peer.hashCode() } }
) { peer ->
Card(
Modifier
.fillMaxWidth()
.padding(horizontal = 12.dp)
.clip(RoundedCornerShape(12.dp))
.animateItemPlacement()
.clickable {
selectedPeerIp = peer.ip
}
) {
Row(
Modifier
.fillMaxWidth()
.padding(vertical = 12.dp, horizontal = 12.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Column {
Text(peer.fqdn)
Text(peer.ip)
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.End
) {
Text(
text = when (peer.connectionStatus) {
"Connected" -> stringResource(R.string.connected)
"Disconnected" -> stringResource(R.string.disconnected)
"Connecting" -> stringResource(R.string.connecting)
else -> stringResource(R.string.unknown)
}
)
Spacer(Modifier.width(8.dp))
Canvas(
Modifier.size(16.dp)
) {
drawCircle(
color = when (peer.connectionStatus ) {
"Connected" -> JetBirdColors.IndicatorColors.Connected
"Disconnected" -> JetBirdColors.IndicatorColors.Disconnected
"Connecting" -> JetBirdColors.IndicatorColors.Connecting
else -> JetBirdColors.IndicatorColors.Disconnected
}
)
}
}
}
}
}
}
if (selectedPeerIp != null) {
val peer = peers.find { it.ip == selectedPeerIp }
AlertDialog(
title = { Text(stringResource(R.string.peer_info)) },
text = {
Column {
Text(stringResource(R.string.peer_ip, peer?.ip.toString()))
Text(stringResource(R.string.peer_fqdn, peer?.fqdn.toString()))
Text(stringResource(R.string.peer_connection_status, peer?.connectionStatus.toString()))
Text(stringResource(R.string.peer_connection_status_update, peer?.connectionStatusUpdate ?: 0))
Text(stringResource(R.string.peer_public_key, peer?.publicKey.toString()))
Text(stringResource(R.string.peer_relayed, peer?.relayed ?: false))
Text(stringResource(R.string.peer_direct, peer?.direct ?: false))
// Text(stringResource(R.string.peer_last_wireguard_handshake, peer?.lastWireguardHandshake.orEmpty()))
Text(stringResource(R.string.peer_bytes_rx, peer?.bytesRx.toString()))
Text(stringResource(R.string.peer_bytes_tx, peer?.bytesTx.toString()))
Text(stringResource(R.string.peer_latency, peer?.latency ?: 0))
Text(stringResource(R.string.peer_rosenpass, peer?.rosenpassEnabled ?: false))
Text(stringResource(R.string.routes, peer?.routes?.joinToString().orEmpty()))
}
},
onDismissRequest = { selectedPeerIp = null },
confirmButton = {
Button(
onClick = {
selectedPeerIp = null
}
) {
Text(stringResource(R.string.close))
}
},
)
}
}

View File

@@ -0,0 +1,27 @@
package dev.bg.jetbird.ui.screens.home
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.bg.jetbird.repository.PreferencesRepository
import dev.bg.jetbird.util.IoDispatcher
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class HomeViewModel @Inject constructor(
private val preferencesRepository: PreferencesRepository,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher
): ViewModel() {
fun hasAuthed() = preferencesRepository.hasAuthed
fun getSetupKey() = preferencesRepository.setupKey
fun updateHasAuthed() {
viewModelScope.launch(ioDispatcher) {
preferencesRepository.hasAuthed = true
preferencesRepository.updateState()
}
}
}

View File

@@ -0,0 +1,173 @@
package dev.bg.jetbird.ui.screens.log
import android.app.Activity
import android.content.Intent
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.AssistChipDefaults
import androidx.compose.material3.ElevatedAssistChip
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.bg.jetbird.R
import dev.bg.jetbird.ui.components.MonospaceText
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import java.io.FileOutputStream
@Composable
fun LogScreen(
viewModel: LogViewModel = hiltViewModel(),
logState: StateFlow<List<String>> = viewModel.logEntries
) {
val ctx = LocalContext.current
val clipboardManager = LocalClipboardManager.current
val scope = rememberCoroutineScope()
val logEntries = logState.collectAsStateWithLifecycle().value
val logWriterLauncher = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) { result ->
if (result.resultCode != Activity.RESULT_OK) return@rememberLauncherForActivityResult
result.data?.data?.let { uri ->
ctx.contentResolver.openFileDescriptor(uri, "w")?.use { fd ->
FileOutputStream(fd.fileDescriptor).use {
it.write(logEntries.joinToString("\n").toByteArray())
}
}
}
}
val netbirdLogWriter = rememberLauncherForActivityResult(
contract = ActivityResultContracts.StartActivityForResult()
) { result ->
if (result.resultCode != Activity.RESULT_OK) return@rememberLauncherForActivityResult
result.data?.data?.let { uri ->
scope.launch(Dispatchers.IO) {
ctx.contentResolver.openFileDescriptor(uri, "w")?.use { fd ->
FileOutputStream(fd.fileDescriptor).use {
it.write(viewModel.dumpNetbirdLog().joinToString("\n").toByteArray())
}
}
}
}
}
Column(
Modifier
.fillMaxSize()
.padding(horizontal = 16.dp)
.padding(bottom = 16.dp)
) {
LazyColumn(
Modifier
.weight(1f)
.horizontalScroll(rememberScrollState())
) {
if (logEntries.isEmpty()) {
item {
MonospaceText(stringResource(R.string.log_empty))
}
} else {
items(logEntries) { log ->
SelectionContainer {
MonospaceText(log)
}
}
}
}
Row(
modifier = Modifier.horizontalScroll(rememberScrollState()),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
ElevatedAssistChip(
onClick = {
if (logEntries.isNotEmpty()) {
clipboardManager.setText(AnnotatedString(logEntries.joinToString("\n")))
}
},
label = { Text(stringResource(R.string.copy_log)) },
colors = AssistChipDefaults.elevatedAssistChipColors(leadingIconContentColor = MaterialTheme.colorScheme.onSurfaceVariant),
leadingIcon = {
Icon(
painterResource(R.drawable.baseline_content_copy_24),
contentDescription = stringResource(R.string.copy_log),
modifier = Modifier.size(AssistChipDefaults.IconSize)
)
}
)
ElevatedAssistChip(
onClick = {
if (logEntries.isNotEmpty()) {
logWriterLauncher.launch(getLogIntent())
}
},
label = { Text(stringResource(R.string.save_log)) },
colors = AssistChipDefaults.elevatedAssistChipColors(leadingIconContentColor = MaterialTheme.colorScheme.onSurfaceVariant),
leadingIcon = {
Icon(
painterResource(R.drawable.baseline_save_24),
contentDescription = stringResource(R.string.save_log),
modifier = Modifier.size(AssistChipDefaults.IconSize)
)
}
)
ElevatedAssistChip(
onClick = { viewModel.clearLog() },
label = { Text(stringResource(R.string.clear_log)) },
colors = AssistChipDefaults.elevatedAssistChipColors(leadingIconContentColor = MaterialTheme.colorScheme.onSurfaceVariant),
leadingIcon = {
Icon(
Icons.Filled.Delete,
contentDescription = stringResource(R.string.copy_log),
modifier = Modifier.size(AssistChipDefaults.IconSize)
)
}
)
ElevatedAssistChip(
onClick = {
netbirdLogWriter.launch(getLogIntent())
},
label = { Text(stringResource(R.string.dump_netbird_log)) },
colors = AssistChipDefaults.elevatedAssistChipColors(leadingIconContentColor = MaterialTheme.colorScheme.onSurfaceVariant),
leadingIcon = {
Icon(
painterResource(R.drawable.baseline_save_24),
contentDescription = stringResource(R.string.dump_netbird_log),
modifier = Modifier.size(AssistChipDefaults.IconSize)
)
}
)
}
}
}
private fun getLogIntent() = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "text/plain"
putExtra(Intent.EXTRA_TITLE, "${("JetBird").replace("\\s+", "_")}_${System.currentTimeMillis() / 1000}.txt")
}

View File

@@ -0,0 +1,31 @@
package dev.bg.jetbird.ui.screens.log
import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.bg.jetbird.repository.LogRepository
import dev.bg.jetbird.util.IoDispatcher
import dev.bg.jetbird.util.Log
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import javax.inject.Inject
@HiltViewModel
class LogViewModel @Inject constructor(
private val logRepository: LogRepository,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher
): ViewModel() {
val logEntries = logRepository.logEntries
suspend fun dumpNetbirdLog(): List<String> = withContext(ioDispatcher) {
val logLines = mutableListOf<String>()
Runtime.getRuntime().exec("logcat -d -s GoLog")
.inputStream
.bufferedReader()
.useLines {
logLines.addAll(it.map { l -> Log.getLogcatLineContent(l) })
}
return@withContext logLines
}
fun clearLog() = logRepository.clear()
}

View File

@@ -0,0 +1,267 @@
package dev.bg.jetbird.ui.screens.routeselector
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ElevatedCard
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.bg.jetbird.R
import dev.bg.jetbird.ui.components.OutlinedTextFieldInputType
import dev.bg.jetbird.ui.components.SettingsSwitch
import dev.bg.jetbird.ui.components.SettingsTile
import dev.bg.jetbird.ui.components.SwipeToDelete
import dev.bg.jetbird.ui.components.TypedOutlinedTextField
@OptIn(ExperimentalFoundationApi::class)
@Composable
fun RouteSelectorScreen(
viewModel: RouteSelectorViewModel = hiltViewModel()
) {
val state = viewModel.state.collectAsStateWithLifecycle().value
val calculatedRoutes = viewModel.calculatedRoutes.collectAsStateWithLifecycle().value
var addRouteOverrideDialog by remember { mutableStateOf(false) }
var viewRoutesDialog by remember { mutableStateOf(false) }
Column(
Modifier
.fillMaxSize()
.padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Text(
stringResource(R.string.route_selector),
fontSize = 36.sp
)
Text(
stringResource(R.string.route_selector_info),
fontSize = 14.sp
)
HorizontalDivider()
SettingsSwitch(
title = stringResource(R.string.route_override),
description = stringResource(R.string.route_override_description),
checked = state.routeOverridesEnabled,
onChange = viewModel::toggleRouteOverridesEnabled
)
SettingsTile(
title = stringResource(R.string.view_routes),
description = stringResource(R.string.view_routes_description),
onClick = { viewRoutesDialog = true }
)
HorizontalDivider()
LazyColumn(
Modifier.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
if (state.routeOverrides.isEmpty()) {
item {
Text(stringResource(R.string.no_route_overrides))
}
}
items(state.routeOverrides.toList()) { route ->
SwipeToDelete(
modifier = Modifier.animateItemPlacement(),
onDeleted = {
viewModel.removeRoute(route)
}
) {
ElevatedCard(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight(),
elevation = CardDefaults.cardElevation(
defaultElevation = 1.dp
)
) {
Row(
Modifier
.fillMaxWidth()
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = route,
fontSize = 24.sp,
)
}
}
}
}
}
AddRouteOverrideDialog(
open = addRouteOverrideDialog,
onDismissRequest = {
addRouteOverrideDialog = false
}
) { route ->
viewModel.addRoute(route)
addRouteOverrideDialog = false
}
ViewRoutesDialog(
open = viewRoutesDialog,
routes = state.routeOverrides,
calculatedRoutes = calculatedRoutes,
onDismissRequest = { viewRoutesDialog = false }
)
}
Box(
Modifier
.fillMaxSize()
.navigationBarsPadding()
.padding(bottom = 12.dp, end = 16.dp),
contentAlignment = Alignment.BottomEnd
) {
FloatingActionButton(
onClick = {
addRouteOverrideDialog = true
}
) {
Icon(
Icons.Filled.Add,
contentDescription = null
)
}
}
}
@Composable
private fun AddRouteOverrideDialog(
open: Boolean,
onDismissRequest: () -> Unit,
onRoute: (route: String) -> Unit
) {
var route by remember { mutableStateOf("") }
var isValidRoute by remember { mutableStateOf(false) }
LaunchedEffect(route) {
isValidRoute = Regex("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(/(3[0-2]|[1-2][0-9]|[0-9]))\$").matches(route) ||
Regex("^s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*(/(12[0-8]|1[0-1][0-9]|[1-9][0-9]|[0-9]))\$").matches(route)
}
if (open) {
AlertDialog(
title = {
Text(stringResource(R.string.add_route))
},
text = {
TypedOutlinedTextField(
value = route,
onValueChange = {
route = it
},
label = { Text(stringResource(R.string.cidr)) },
placeholder = { Text(stringResource(R.string.example_cidr)) },
inputType = OutlinedTextFieldInputType.Any,
maxLines = 1
)
},
onDismissRequest = onDismissRequest,
dismissButton = {
OutlinedButton(
onClick = {
route = ""
onDismissRequest()
}
) {
Text(stringResource(R.string.cancel))
}
},
confirmButton = {
Button(
onClick = {
onRoute(route)
route = ""
},
enabled = isValidRoute
) {
Text(stringResource(R.string.add_route))
}
}
)
}
}
@Composable
private fun ViewRoutesDialog(
open: Boolean,
routes: Set<String>,
calculatedRoutes: Set<String>,
onDismissRequest: () -> Unit
) {
if (open) {
AlertDialog(
modifier = Modifier.padding(vertical = 16.dp),
title = {
Text(stringResource(R.string.add_route))
},
text = {
LazyColumn(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
item {
Column(
verticalArrangement = Arrangement.spacedBy(4.dp)
) {
Text(
stringResource(R.string.upstream_routes),
fontSize = 16.sp
)
Text(
stringResource(R.string.your_overrides, routes.joinToString()),
fontSize = 16.sp
)
HorizontalDivider()
}
}
items(calculatedRoutes.toList()) { route ->
Text(
route,
fontSize = 16.sp
)
}
}
},
onDismissRequest = onDismissRequest,
confirmButton = {
Button(
onClick = onDismissRequest
) {
Text(stringResource(R.string.close))
}
}
)
}
}

View File

@@ -0,0 +1,92 @@
package dev.bg.jetbird.ui.screens.routeselector
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.bg.jetbird.repository.PreferencesRepository
import dev.bg.jetbird.util.DefaultDispatcher
import dev.bg.jetbird.util.IoDispatcher
import dev.bg.jetbird.util.calculateTunneledRoutes
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject
@HiltViewModel
class RouteSelectorViewModel @Inject constructor(
private val preferencesRepository: PreferencesRepository,
@DefaultDispatcher private val defaultDispatcher: CoroutineDispatcher,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher
): ViewModel() {
val state = preferencesRepository.state
private val _calculatedRoutes: MutableStateFlow<Set<String>> = MutableStateFlow(emptySet())
val calculatedRoutes: StateFlow<Set<String>>
get() = _calculatedRoutes.asStateFlow()
init {
viewModelScope.launch {
calculateRoutes()
}
}
fun toggleRouteOverridesEnabled(enabled: Boolean) {
viewModelScope.launch(ioDispatcher) {
preferencesRepository.routeOverridesEnabled = enabled
preferencesRepository.updateState()
}
}
fun addRoute(route: String) {
viewModelScope.launch {
val routes = preferencesRepository
.routeOverrides
.toMutableSet()
.apply {
add(route)
}
preferencesRepository.routeOverrides = routes
preferencesRepository.updateState()
calculateRoutes(routes)
}
}
fun removeRoute(route: String) {
viewModelScope.launch {
withContext(ioDispatcher) {
val routes = preferencesRepository
.routeOverrides
.toMutableSet()
.apply {
removeIf { r -> r == route }
}
preferencesRepository.routeOverrides = routes
preferencesRepository.updateState()
calculateRoutes(routes)
}
}
}
private suspend fun calculateRoutes(
routes: Set<String>? = null
) {
if (routes == null) {
var r: Set<String>
withContext(ioDispatcher) {
r = preferencesRepository.routeOverrides
}
withContext(defaultDispatcher) {
_calculatedRoutes.update { calculateTunneledRoutes(setOf("0.0.0.0/0", "::/0"), r) }
}
} else {
withContext(defaultDispatcher) {
_calculatedRoutes.update { calculateTunneledRoutes(setOf("0.0.0.0/0", "::/0"), routes) }
}
}
}
}

View File

@@ -0,0 +1,476 @@
package dev.bg.jetbird.ui.screens.settings
import android.content.Intent
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.net.Uri
import android.provider.Settings
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.Checkbox
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.graphics.drawable.toBitmap
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.bg.jetbird.BuildConfig
import dev.bg.jetbird.LocalNavController
import dev.bg.jetbird.LocalSnackbar
import dev.bg.jetbird.R
import dev.bg.jetbird.Route
import dev.bg.jetbird.repository.PreferencesState
import dev.bg.jetbird.ui.components.DeleteAlertDialog
import dev.bg.jetbird.ui.components.OutlinedTextFieldInputType
import dev.bg.jetbird.ui.components.SettingsSection
import dev.bg.jetbird.ui.components.SettingsSwitch
import dev.bg.jetbird.ui.components.SettingsTile
import dev.bg.jetbird.ui.components.SettingsTileWithValue
import dev.bg.jetbird.ui.components.TextFieldAlertDialog
import dev.bg.jetbird.util.ktx.getConfigPath
import dev.bg.jetbird.util.ktx.navigate
import dev.bg.jetbird.util.ktx.toStringOrNotSet
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import timber.log.Timber
import java.io.File
import java.io.IOException
@Composable
fun SettingsScreen(
viewModel: SettingsViewModel = hiltViewModel(),
preferencesState: StateFlow<PreferencesState> = viewModel.state
) {
val ctx = LocalContext.current
val navController = LocalNavController.current
val snackbar = LocalSnackbar.current
val scope = rememberCoroutineScope()
val scrollState = rememberScrollState()
val state = preferencesState.collectAsStateWithLifecycle().value
fun deleteConfigFile() {
val config = File(ctx.getConfigPath())
try {
when (config.delete()) {
true -> scope.launch { snackbar.showSnackbar(ctx.getString(R.string.removed_netbird_config)) }
false -> scope.launch { snackbar.showSnackbar(ctx.getString(R.string.failed_remove_netbird_config)) }
}
} catch (e: IOException) {
Timber.d("Failed to delete NetBird config file: $e")
scope.launch {
snackbar.showSnackbar(ctx.getString(R.string.failed_remove_netbird_config))
}
}
}
Column(
Modifier
.fillMaxSize()
.padding(horizontal = 16.dp)
.verticalScroll(scrollState)
) {
Text(
stringResource(R.string.settings),
fontSize = 36.sp,
fontWeight = FontWeight.W400
)
SettingsSection(
title = stringResource(R.string.netbird)
) {
var managementUrlDialog by remember { mutableStateOf(false) }
var preSharedKeyDialog by remember { mutableStateOf(false) }
var configViewDialog by remember { mutableStateOf(false) }
var engineLoggingWarning by remember { mutableStateOf(false) }
SettingsTileWithValue(
title = stringResource(R.string.management_server),
description = when {
state.managementUrl == null -> null
state.ssoSupported -> stringResource(R.string.sso_supported)
!state.ssoSupported -> stringResource(R.string.sso_unsupported)
else -> null
},
value = state.managementUrl.toStringOrNotSet(ctx),
onClick = { managementUrlDialog = true }
)
TextFieldAlertDialog(
open = managementUrlDialog,
title = stringResource(R.string.management_server),
label = stringResource(R.string.management_server),
enabled = false,
initialValue = state.managementUrl,
supportingText = stringResource(R.string.reset_to_change_management_server),
inputType = OutlinedTextFieldInputType.Any,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri),
onDismissRequest = { managementUrlDialog = false },
onEntered = {}
)
SettingsTileWithValue(
title = stringResource(R.string.pre_shared_key),
value = state.preSharedKey.toStringOrNotSet(ctx),
onClick = { preSharedKeyDialog = true }
)
TextFieldAlertDialog(
open = preSharedKeyDialog,
title = stringResource(R.string.pre_shared_key),
label = stringResource(R.string.pre_shared_key),
initialValue = state.preSharedKey,
inputType = OutlinedTextFieldInputType.Any,
onDismissRequest = { preSharedKeyDialog = false },
onEntered = { key -> viewModel.updatePreSharedKey(ctx.getConfigPath(), key) }
)
SettingsTileWithValue(
title = stringResource(R.string.setup_key),
value = state.setupKey.toStringOrNotSet(ctx),
)
SettingsSwitch(
title = stringResource(R.string.rosenpass),
checked = state.rosenpass,
onChange = { viewModel.toggleRosenpass(ctx.getConfigPath(), it) }
)
AnimatedVisibility(state.rosenpass) {
SettingsSwitch(
title = stringResource(R.string.permissive_rosenpass),
description = stringResource(R.string.permissive_rosenpass_description),
checked = state.rosenpassPermissive,
onChange = { viewModel.toggleRosenpassPermissive(ctx.getConfigPath(), it) }
)
}
SettingsSwitch(
title = stringResource(R.string.enable_logging),
description = stringResource(R.string.enable_logging_description_netbird),
checked = state.engineLogging,
onChange = viewModel::toggleEngineLogging
)
AnimatedVisibility(state.engineLogging) {
Column(
Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
SettingsSwitch(
title = stringResource(R.string.enable_verbose_logging),
description = stringResource(R.string.enable_verbose_logging_description_netbird),
checked = state.verboseEngineLogging,
onChange = viewModel::toggleVerboseEngineLogging
)
SettingsSwitch(
title = stringResource(R.string.enable_live_logging),
description = stringResource(R.string.enable_live_logging_description),
checked = state.liveEngineLogging,
onChange = {
if (it) {
engineLoggingWarning = true
}
viewModel.toggleLiveEngineLogging(it)
}
)
}
}
LiveLoggingWarning(
visible = engineLoggingWarning,
onDismissRequest = { engineLoggingWarning = false }
)
SettingsTile(
title = stringResource(R.string.view_config),
description = stringResource(R.string.view_config_description),
onClick = { configViewDialog = true }
)
ConfigViewDialog(
visible = configViewDialog,
onDismissRequest = { configViewDialog = false }
)
}
HorizontalDivider()
SettingsSection(
title = stringResource(R.string.app_name)
) {
var excludeAppsDialog by remember { mutableStateOf(false) }
SettingsSwitch(
title = stringResource(R.string.enable_logging),
description = stringResource(R.string.enable_logging_description),
checked = state.logging,
onChange = viewModel::toggleLogging
)
AnimatedVisibility(state.logging) {
SettingsSwitch(
title = stringResource(R.string.enable_verbose_logging),
description = stringResource(R.string.enable_verbose_logging_description),
checked = state.verboseLogging,
onChange = viewModel::toggleVerboseLogging
)
}
SettingsTile(
title = stringResource(R.string.exclude_apps),
description = stringResource(R.string.exclude_apps_description, state.excludedApps.size),
onClick = { excludeAppsDialog = true }
)
ExcludeAppsDialog(
visible = excludeAppsDialog,
initialPackages = state.excludedApps,
onDismissRequest = { excludeAppsDialog = false },
onSelected = { packageNames ->
excludeAppsDialog = false
viewModel.updateExcludedApps(packageNames)
}
)
SettingsTile(
title = stringResource(R.string.route_selector),
description = stringResource(R.string.route_selector_description, state.routeOverrides.size),
onClick = { navController.navigate(Route.RouteSelector) }
)
}
HorizontalDivider()
SettingsSection(
title = stringResource(R.string.app)
) {
var wipeConfigDialog by remember { mutableStateOf(false) }
var wipeAllDialog by remember { mutableStateOf(false) }
SettingsTile(
title = stringResource(R.string.reset_netbird_config),
description = stringResource(R.string.reset_netbird_config_description),
onClick = {
wipeConfigDialog = true
}
)
DeleteAlertDialog(
title = stringResource(R.string.reset_netbird_config),
description = stringResource(R.string.reset_netbird_config_description),
open = wipeConfigDialog,
onDismissRequest = { wipeConfigDialog = false },
onDelete = {
wipeConfigDialog = false
deleteConfigFile()
}
)
SettingsTile(
title = stringResource(R.string.reset_app),
description = stringResource(R.string.reset_app_description),
onClick = {
wipeAllDialog = true
}
)
DeleteAlertDialog(
title = stringResource(R.string.reset_app),
description = stringResource(R.string.reset_app_description),
open = wipeAllDialog,
onDismissRequest = { wipeAllDialog = false },
onDelete = {
wipeAllDialog = false
viewModel.resetPreferences()
deleteConfigFile()
navController.navigate(Route.Setup)
}
)
}
HorizontalDivider()
SettingsSection(
title = stringResource(R.string.about)
) {
SettingsTile(
title = stringResource(R.string.app_name),
description = BuildConfig.APPLICATION_ID,
onClick = {
ctx.startActivity(
Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
data = Uri.parse("package:${ctx.packageName}")
}
)
}
)
SettingsTile(
title = stringResource(R.string.about_version, BuildConfig.VERSION_NAME),
description = stringResource(
R.string.about_build,
BuildConfig.VERSION_CODE
)
)
SettingsTile(
title = stringResource(R.string.about_netbird_version),
description = BuildConfig.NETBIRD_COMMIT
)
SettingsTile(
title = stringResource(R.string.credits),
description = stringResource(R.string.credits_description),
onClick = {
navController.navigate(Route.Credits)
}
)
}
}
}
@Composable
private fun LiveLoggingWarning(
visible: Boolean,
onDismissRequest: () -> Unit
) {
if (visible) {
AlertDialog(
modifier = Modifier.padding(vertical = 16.dp),
onDismissRequest = onDismissRequest,
title = { Text(stringResource(R.string.warning)) },
text = { Text(stringResource(R.string.engine_logging_warning)) },
confirmButton = {
Button(onClick = onDismissRequest) {
Text(stringResource(R.string.close))
}
}
)
}
}
@Composable
private fun ConfigViewDialog(
visible: Boolean,
onDismissRequest: () -> Unit
) {
val ctx = LocalContext.current
if (visible) {
AlertDialog(
modifier = Modifier.padding(vertical = 16.dp),
onDismissRequest = onDismissRequest,
text = {
Column(Modifier.verticalScroll(rememberScrollState())) {
Text(File(ctx.getConfigPath()).readText())
}
},
confirmButton = {
Button(onClick = onDismissRequest) {
Text(stringResource(R.string.close))
}
}
)
}
}
@Composable
private fun ExcludeAppsDialog(
visible: Boolean,
initialPackages: Set<String>,
onDismissRequest: () -> Unit,
onSelected: (packageNames: Set<String>) -> Unit
) {
val ctx = LocalContext.current
val packageManager = ctx.packageManager
val installedPackages = remember {
packageManager
.getInstalledApplications(PackageManager.GET_META_DATA)
.toList()
.filter { it.flags and ApplicationInfo.FLAG_SYSTEM == 0 && it.packageName != ctx.packageName }
.sortedBy { it.loadLabel(packageManager).toString() }
}
val selectedPackages = remember {
mutableStateListOf(
*initialPackages.map {
packageManager.getApplicationInfo(it, PackageManager.GET_META_DATA)
}.toTypedArray()
)
}
fun toggleSelected(app: ApplicationInfo) {
if (!selectedPackages.any { p -> p.packageName == app.packageName }) {
selectedPackages.add(app)
} else {
selectedPackages.removeIf { p -> p.packageName == app.packageName }
}
}
if (visible) {
AlertDialog(
modifier = Modifier.padding(vertical = 16.dp),
onDismissRequest = onDismissRequest,
text = {
LazyColumn(
Modifier.fillMaxSize()
) {
items(installedPackages) {
Row(
Modifier
.fillMaxWidth()
.clickable {
toggleSelected(it)
},
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Row(
verticalAlignment = Alignment.CenterVertically
) {
Image(
it.loadIcon(packageManager).toBitmap().asImageBitmap(),
modifier = Modifier.size(36.dp),
contentDescription = null
)
Spacer(Modifier.width(8.dp))
Text(it.loadLabel(packageManager).toString())
}
Checkbox(
checked = selectedPackages.any { p -> p.packageName == it.packageName },
onCheckedChange = { _ ->
toggleSelected(it)
}
)
}
}
}
},
dismissButton = {
OutlinedButton(onClick = onDismissRequest) {
Text(stringResource(R.string.cancel))
}
},
confirmButton = {
Button(
onClick = {
onSelected(selectedPackages.map { it.packageName }.toSet())
}
) {
Text(stringResource(R.string.exclude))
}
}
)
}
}

View File

@@ -0,0 +1,128 @@
package dev.bg.jetbird.ui.screens.settings
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.bg.jetbird.repository.LogRepository
import dev.bg.jetbird.repository.PreferencesRepository
import dev.bg.jetbird.util.IoDispatcher
import io.netbird.android.Preferences
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject
@HiltViewModel
class SettingsViewModel @Inject constructor(
private val preferencesRepository: PreferencesRepository,
private val logRepository: LogRepository,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher
): ViewModel() {
val state = preferencesRepository.state
fun updatePreSharedKey(
configPath: String,
key: String?
) {
log("Updating pre-shared key to $key in config")
viewModelScope.launch(ioDispatcher) {
withContext(ioDispatcher) {
val preferences = Preferences(configPath)
preferences.preSharedKey = key
preferences.commit()
}
preferencesRepository.preSharedKey = key
updatePreferenceState()
}
}
fun toggleRosenpass(
configPath: String,
enabled: Boolean
) {
log(if (enabled) "Enabling rosenpass in config" else "Disabling rosenpass in config")
viewModelScope.launch(ioDispatcher) {
withContext(ioDispatcher) {
val preferences = Preferences(configPath)
preferences.setRosenpass(enabled)
preferences.commit()
}
preferencesRepository.rosenpass = enabled
if (!enabled) {
toggleRosenpassPermissive(configPath, false)
}
updatePreferenceState()
}
}
fun toggleRosenpassPermissive(
configPath: String,
enabled: Boolean
) {
log(if (enabled) "Enabling rosenpass permissive in config" else "Disabling rosenpass permissive in config")
viewModelScope.launch(ioDispatcher) {
withContext(ioDispatcher) {
val preferences = Preferences(configPath)
preferences.setRosenpassPermissive(enabled)
preferences.commit()
}
preferencesRepository.rosenpassPermissive = enabled
updatePreferenceState()
}
}
fun toggleLogging(enabled: Boolean) {
preferencesRepository.logging = enabled
launchUpdatePreferenceState()
}
fun toggleVerboseLogging(enabled: Boolean) {
preferencesRepository.verboseLogging = enabled
launchUpdatePreferenceState()
}
fun toggleEngineLogging(enabled: Boolean) {
preferencesRepository.engineLogging = enabled
launchUpdatePreferenceState()
}
fun toggleVerboseEngineLogging(enabled: Boolean) {
preferencesRepository.verboseEngineLogging = enabled
launchUpdatePreferenceState()
}
fun toggleLiveEngineLogging(enabled: Boolean) {
preferencesRepository.liveEngineLogging = enabled
launchUpdatePreferenceState()
}
fun updateExcludedApps(packageNames: Set<String>) {
preferencesRepository.excludedApps = packageNames
launchUpdatePreferenceState()
}
fun resetPreferences() {
log("Resetting JetBird preferences")
viewModelScope.launch(ioDispatcher) {
preferencesRepository.reset()
}
}
private suspend fun updatePreferenceState() {
preferencesRepository.updateState()
}
private fun launchUpdatePreferenceState() {
viewModelScope.launch(ioDispatcher) {
updatePreferenceState()
}
}
private fun log(message: String) {
if (preferencesRepository.state.value.verboseLogging) {
logRepository.log(message)
}
}
}

View File

@@ -0,0 +1,265 @@
package dev.bg.jetbird.ui.screens.setup
import androidx.compose.animation.AnimatedContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Button
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.bg.jetbird.LocalLayoutType
import dev.bg.jetbird.LocalNavController
import dev.bg.jetbird.LocalSnackbar
import dev.bg.jetbird.R
import dev.bg.jetbird.Route
import dev.bg.jetbird.data.LayoutType
import dev.bg.jetbird.ui.components.LoadingButton
import dev.bg.jetbird.util.ktx.clearAndNavigate
import dev.bg.jetbird.util.ktx.getConfigPath
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.receiveAsFlow
@Composable
fun SetupScreen(
viewModel: SetupViewModel = hiltViewModel(),
errors: Flow<String> = viewModel.errors.receiveAsFlow()
) {
val ctx = LocalContext.current
val snackbar = LocalSnackbar.current
val navController = LocalNavController.current
val layoutType = LocalLayoutType.current
val loading = viewModel.loading.collectAsStateWithLifecycle().value
val ssoSupport = viewModel.ssoSupported.collectAsStateWithLifecycle().value
val setupComplete = viewModel.setupComplete.collectAsStateWithLifecycle().value
LaunchedEffect(Unit) {
errors.onEach {
snackbar.showSnackbar(it)
}.collect()
}
LaunchedEffect(setupComplete) {
if (setupComplete) {
snackbar.showSnackbar(ctx.getString(R.string.setup_key_saved))
navController.clearAndNavigate(Route.Home)
}
}
when (layoutType) {
LayoutType.WideLandscape,
LayoutType.PanelLandscape -> {
Row(
Modifier
.fillMaxSize()
.imePadding(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceEvenly
) {
Welcome(Modifier.weight(1f))
VerticalDivider(Modifier.fillMaxHeight(0.6f))
SetupInfo(
loading,
ssoSupport,
updateManagementUrl = { managementUrl ->
viewModel.updateManagementUrl(managementUrl, ssoSupport ?: false)
},
checkManagementUrl = { managementUrl ->
viewModel.checkManagementUrl(ctx.getConfigPath(), managementUrl)
},
updateSetupKey = { managementUrl, setupKey ->
viewModel.updateSetupKey(
configPath = ctx.getConfigPath(),
managementUrl = managementUrl,
setupKey = setupKey,
ssoSupported = ssoSupport ?: false
)
},
modifier = Modifier.weight(1f)
)
}
}
else -> {
Column(
Modifier
.fillMaxSize()
.imePadding(),
verticalArrangement = Arrangement.SpaceAround,
horizontalAlignment = Alignment.CenterHorizontally
) {
Welcome()
SetupInfo(
loading,
ssoSupport,
updateManagementUrl = { managementUrl ->
viewModel.updateManagementUrl(managementUrl, ssoSupport ?: false)
},
checkManagementUrl = { managementUrl ->
viewModel.checkManagementUrl(ctx.getConfigPath(), managementUrl)
},
updateSetupKey = { managementUrl, setupKey ->
viewModel.updateSetupKey(
configPath = ctx.getConfigPath(),
managementUrl = managementUrl,
setupKey = setupKey,
ssoSupported = ssoSupport ?: false
)
}
)
}
}
}
}
@Composable
private fun Welcome(
modifier: Modifier = Modifier
) {
Column(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = stringResource(R.string.welcome_jetbird),
fontSize = 24.sp,
fontWeight = FontWeight.SemiBold
)
Icon(
painterResource(R.drawable.ic_launcher_monochrome),
modifier = Modifier.size(196.dp),
tint = MaterialTheme.colorScheme.primary,
contentDescription = stringResource(R.string.app_name),
)
}
}
@Composable
private fun SetupInfo(
loading: Boolean,
ssoSupport: Boolean?,
updateManagementUrl: (managementUrl: String) -> Unit,
checkManagementUrl: (managementUrl: String) -> Unit,
updateSetupKey: (managementUrl: String, setupKey: String) -> Unit,
modifier: Modifier = Modifier
) {
val focusManager = LocalFocusManager.current
val navController = LocalNavController.current
val managementUrlRegex = remember { Regex("^https://.*$") }
val setupKeyRegex = remember { Regex("^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$") }
var managementUrl by remember { mutableStateOf("") }
var setupKey by remember { mutableStateOf("") }
AnimatedContent(
targetState = ssoSupport,
modifier = modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
label = "Setup animation"
) { sso ->
when (sso) {
null -> {
Column(
Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(24.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
stringResource(R.string.get_started_url),
textAlign = TextAlign.Center
)
OutlinedTextField(
value = managementUrl,
onValueChange = { managementUrl = it },
placeholder = { Text(stringResource(R.string.management_url)) }
)
LoadingButton(
onClick = {
focusManager.clearFocus()
checkManagementUrl(managementUrl)
},
loading = loading,
enabled = !loading && managementUrl.matches(managementUrlRegex)
) {
Text(stringResource(R.string.connect))
}
}
}
else -> {
Column(
Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(24.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
if (sso) {
Text(stringResource(R.string.setup_sso_supported))
} else {
Text(stringResource(R.string.setup_sso_unsupported))
}
Button(
onClick = {
updateManagementUrl(managementUrl)
navController.clearAndNavigate(Route.Home)
},
enabled = sso
) {
Text(stringResource(R.string.use_sso))
}
HorizontalDivider()
if (sso) {
Text(stringResource(R.string.setup_setup_key_alternative))
} else {
Text(stringResource(R.string.setup_setup_key_required))
}
OutlinedTextField(
value = setupKey,
onValueChange = { setupKey = it },
placeholder = { Text(stringResource(R.string.setup_key)) }
)
Button(
onClick = {
focusManager.clearFocus()
updateSetupKey(managementUrl, setupKey)
navController.clearAndNavigate(Route.Home)
},
enabled = setupKey.matches(setupKeyRegex)
) {
Text(stringResource(R.string.use_setup_key))
}
}
}
}
}
}

View File

@@ -0,0 +1,98 @@
package dev.bg.jetbird.ui.screens.setup
import android.os.Build
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.bg.jetbird.repository.PreferencesRepository
import dev.bg.jetbird.util.IoDispatcher
import io.netbird.android.Android
import io.netbird.android.ErrListener
import io.netbird.android.SSOListener
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber
import javax.inject.Inject
@HiltViewModel
class SetupViewModel @Inject constructor(
private val preferencesRepository: PreferencesRepository,
@IoDispatcher private val ioDispatcher: CoroutineDispatcher
): ViewModel() {
private val _loading: MutableStateFlow<Boolean> = MutableStateFlow(false)
val loading: StateFlow<Boolean>
get() = _loading.asStateFlow()
private val _ssoSupported: MutableStateFlow<Boolean?> = MutableStateFlow(null)
val ssoSupported: StateFlow<Boolean?>
get() = _ssoSupported.asStateFlow()
private val _setupComplete: MutableStateFlow<Boolean> = MutableStateFlow(false)
val setupComplete: StateFlow<Boolean>
get() = _setupComplete.asStateFlow()
val errors = Channel<String>(Channel.UNLIMITED)
fun checkManagementUrl(
configPath: String,
url: String
) {
_loading.update { true }
val auth = Android.newAuth(configPath, url)
auth.saveConfigIfSSOSupported(object : SSOListener {
override fun onSuccess(sso: Boolean) {
_loading.update { false }
_ssoSupported.update { sso }
}
override fun onError(e: Exception?) {
_loading.update { false }
viewModelScope.launch { errors.send(e?.message ?: "Unknown exception") }
Timber.d("Failed to login: $e")
}
})
}
fun updateManagementUrl(
url: String,
ssoSupported: Boolean
) {
viewModelScope.launch(ioDispatcher) {
preferencesRepository.managementUrl = url
preferencesRepository.ssoSupported = ssoSupported
preferencesRepository.updateState()
}
}
fun updateSetupKey(
configPath: String,
managementUrl: String,
setupKey: String,
ssoSupported: Boolean = false
) {
viewModelScope.launch(ioDispatcher) {
val auth = Android.newAuth(configPath, managementUrl)
preferencesRepository.managementUrl = managementUrl
preferencesRepository.setupKey = setupKey
preferencesRepository.ssoSupported = ssoSupported
preferencesRepository.updateState()
auth.loginWithSetupKeyAndSaveConfig(
object: ErrListener {
override fun onSuccess() {
_setupComplete.update { true }
}
override fun onError(e: java.lang.Exception?) {
viewModelScope.launch { errors.send(e?.message ?: "Unknown exception") }
}
},
setupKey,
Build.PRODUCT
)
}
}
}

View File

@@ -0,0 +1,11 @@
package dev.bg.jetbird.ui.theme
import androidx.compose.ui.graphics.Color
val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
val Pink80 = Color(0xFFEFB8C8)
val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)

View File

@@ -0,0 +1,58 @@
package dev.bg.jetbird.ui.theme
import android.app.Activity
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
private val DarkColorScheme = darkColorScheme(
primary = Purple80,
secondary = PurpleGrey80,
tertiary = Pink80
)
private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40
)
@Composable
fun JetBirdTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> DarkColorScheme
else -> LightColorScheme
}
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
val window = (view.context as Activity).window
window.statusBarColor = colorScheme.primary.toArgb()
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme
}
}
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
content = content
)
}

View File

@@ -0,0 +1,17 @@
package dev.bg.jetbird.ui.theme
import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
val Typography = Typography(
bodyLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp
)
)

View File

@@ -0,0 +1,11 @@
package dev.bg.jetbird.util
import javax.inject.Qualifier
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class DefaultDispatcher
@Qualifier
@Retention(AnnotationRetention.RUNTIME)
annotation class IoDispatcher

View File

@@ -0,0 +1,74 @@
package dev.bg.jetbird.util
import android.content.res.Configuration
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.platform.LocalConfiguration
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.window.core.layout.WindowHeightSizeClass
import androidx.window.core.layout.WindowWidthSizeClass
import dev.bg.jetbird.data.LayoutType
@Composable
fun OnLifecycleEvent(
onEvent: (owner: LifecycleOwner, event: Lifecycle.Event) -> Unit
) {
val eventHandler = rememberUpdatedState(onEvent)
val lifecycleOwner = rememberUpdatedState(LocalLifecycleOwner.current)
DisposableEffect(lifecycleOwner.value) {
val lifecycle = lifecycleOwner.value.lifecycle
val observer = LifecycleEventObserver { owner, event ->
eventHandler.value(owner, event)
}
lifecycle.addObserver(observer)
onDispose {
lifecycle.removeObserver(observer)
}
}
}
@Composable
fun OnLayoutChange(
onEvent: (layoutType: LayoutType) -> Unit
) {
val configuration = LocalConfiguration.current
val windowSize = currentWindowAdaptiveInfo().windowSizeClass
LaunchedEffect(configuration) {
snapshotFlow { configuration.orientation }
.collect { orientation ->
when (orientation) {
Configuration.ORIENTATION_PORTRAIT -> {
onEvent(
when (windowSize.windowWidthSizeClass) {
WindowWidthSizeClass.COMPACT -> LayoutType.CompactPortrait
WindowWidthSizeClass.MEDIUM,
WindowWidthSizeClass.EXPANDED -> LayoutType.WidePortrait
else -> LayoutType.CompactPortrait
}
)
}
Configuration.ORIENTATION_LANDSCAPE -> {
onEvent(
when {
windowSize.windowWidthSizeClass == WindowWidthSizeClass.COMPACT && windowSize.windowHeightSizeClass == WindowHeightSizeClass.COMPACT -> LayoutType.CompactLandscape
windowSize.windowWidthSizeClass == WindowWidthSizeClass.MEDIUM -> LayoutType.WideLandscape
windowSize.windowWidthSizeClass == WindowWidthSizeClass.EXPANDED -> LayoutType.PanelLandscape
else -> LayoutType.CompactLandscape
}
)
}
else -> onEvent(LayoutType.CompactLandscape)
}
}
}
}

View File

@@ -0,0 +1,9 @@
package dev.bg.jetbird.util
object Log {
fun getLogcatLineContent(line: String): String {
val s = line.split("GoLog")
if (s.size != 2) return line
return "[${s.first().split(" ")[1]}] ${s.last().drop(5)}"
}
}

View File

@@ -0,0 +1,20 @@
package dev.bg.jetbird.util
import kotlinx.coroutines.Job
class ReplaceableJob {
private var job: Job? = null
val isActive get() = job?.isActive ?: false
@Synchronized
operator fun plusAssign(newJob: Job) {
cancel()
job = newJob
}
fun cancel() {
job?.cancel()
job = null
}
}

View File

@@ -0,0 +1,35 @@
package dev.bg.jetbird.util
import inet.ipaddr.IPAddress
import inet.ipaddr.IPAddressString
fun calculateTunneledRoutes(
allowedIps: Set<String>,
disallowedIps: Set<String>
): Set<String> {
var init = allowedIps.map { IPAddressString(it) }.toSet()
disallowedIps.map { IPAddressString(it) }.forEach { disallowed ->
val new = mutableSetOf<IPAddress>()
init.forEach { allowed ->
if (allowed.ipVersion == disallowed.ipVersion) {
if (allowed.contains(disallowed)) {
new.addAll(
allowed
.getAddress()
.subtract(disallowed.getAddress())
.flatMap { listOf(*it.spanWithPrefixBlocks()) }
)
} else {
new.add(allowed.getAddress())
}
} else {
new.add(allowed.getAddress())
}
}
init = new.map { it.toAddressString() }.toSet()
}
return init
.sortedBy { it.networkPrefixLength }
.map { it.getAddress().toString() }
.toSet()
}

View File

@@ -0,0 +1,21 @@
package dev.bg.jetbird.util.ktx
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
fun Context.getConfigPath(): String = "${filesDir.path}/netbird.cfg"
fun Context.hasOtherAlwaysOnVpn(): Boolean {
val connectivityManager = (getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager)
val network = connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork) ?: return false
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
network.hasTransport(NetworkCapabilities.TRANSPORT_VPN) &&
network.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED) &&
network.hasCapability(NetworkCapabilities.NET_CAPABILITY_FOREGROUND)
} else {
network.hasTransport(NetworkCapabilities.TRANSPORT_VPN) &&
network.hasCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
}
}

View File

@@ -0,0 +1,26 @@
package dev.bg.jetbird.util.ktx
import io.netbird.android.DNSList
import timber.log.Timber
import java.net.InetAddress
fun List<InetAddress>.toDnsList(): DNSList {
val list = DNSList()
this.forEach { list.add(it.hostAddress) }
return list
}
fun List<InetAddress>.addFallbackDns(
dnsHostname: String
): DNSList {
if (this.isEmpty()) return toDnsList()
if (!this[0].isLinkLocalAddress) return toDnsList()
val dns = this.toMutableList()
runCatching {
Timber.d("Adding fallback DNS")
dns.add(InetAddress.getByName(dnsHostname))
}.onFailure {
Timber.d("Failed to add DNS server $dnsHostname")
}
return dns.toDnsList()
}

View File

@@ -0,0 +1,14 @@
package dev.bg.jetbird.util.ktx
import androidx.compose.ui.Modifier
fun Modifier.conditional(
condition: Boolean,
modifier: Modifier.() -> Modifier
) : Modifier {
return if (condition) {
then(modifier(Modifier))
} else {
this
}
}

View File

@@ -0,0 +1,18 @@
package dev.bg.jetbird.util.ktx
import androidx.compose.runtime.Composable
import androidx.navigation.NamedNavArgument
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavDeepLink
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import dev.bg.jetbird.Route
fun NavGraphBuilder.composable(
route: Route,
arguments: List<NamedNavArgument> = emptyList(),
deepLinks: List<NavDeepLink> = emptyList(),
content: @Composable (NavBackStackEntry) -> Unit
) {
composable(route.route, arguments, deepLinks, content)
}

View File

@@ -0,0 +1,14 @@
package dev.bg.jetbird.util.ktx
import androidx.navigation.NavHostController
import dev.bg.jetbird.Route
fun NavHostController.navigate(route: Route) {
return this.navigate(route.route)
}
fun NavHostController.clearAndNavigate(route: Route) {
return this.navigate(route.route) {
popUpTo(0)
}
}

View File

@@ -0,0 +1,32 @@
package dev.bg.jetbird.util.ktx
import dev.bg.jetbird.data.model.Peer
import io.netbird.android.PeerInfoArray
import java.text.SimpleDateFormat
import java.util.Locale
fun PeerInfoArray?.toPeerList(): List<Peer> {
if (this == null) return emptyList()
val peers = mutableListOf<Peer>()
for (i in 0..<size()) {
val peer = this[i]
peers.add(
Peer(
ip = peer.ip,
fqdn = peer.fqdn,
connectionStatus = peer.connStatus,
connectionStatusUpdate = if (peer.connStatusUpdate > 0) SimpleDateFormat("dd'/'MM HH:mm", Locale.getDefault()).format(peer.connStatusUpdate * 1000) else "",
publicKey = peer.pubKey,
relayed = peer.relayed,
direct = peer.direct,
lastWireguardHandshake = peer.lastWireguardHandshake.toString(),
bytesTx = peer.bytesTx,
bytesRx = peer.bytesRx,
latency = peer.latency,
rosenpassEnabled = peer.rosenpassEnabled,
routes = peer.routes.split(";")
)
)
}
return peers
}

View File

@@ -0,0 +1,8 @@
package dev.bg.jetbird.util.ktx
import android.content.Context
import dev.bg.jetbird.R
fun String?.toStringOrNotSet(
ctx: Context
) = this ?: ctx.getString(R.string.not_set)

View File

@@ -0,0 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="24dp"
android:height="24dp"
android:viewportWidth="1080"
android:viewportHeight="1080"
android:tint="#FFFFFF">
<group android:scaleX="1.104"
android:scaleY="1.104"
android:translateX="-56.16"
android:translateY="-56.16">
<path
android:fillColor="#FF000000"
android:pathData="M922,622.6C916.5,622.6 912,618.1 912,612.6C912,607.1 916.5,602.6 922,602.6L972,602.6C977.5,602.6 982,607.1 982,612.6C982,618.1 977.5,622.6 972,622.6L922,622.6ZM872,687.4C866.5,687.4 862,682.9 862,677.4C862,671.9 866.5,667.4 872,667.4L972,667.4C977.5,667.4 982,671.9 982,677.4C982,682.9 977.5,687.4 972,687.4L872,687.4ZM772,752.2C766.5,752.2 762,747.7 762,742.2C762,736.7 766.5,732.2 772,732.2L972,732.2C977.5,732.2 982,736.7 982,742.2C982,747.7 977.5,752.2 972,752.2L772,752.2ZM672,817C666.5,817 662,812.5 662,807C662,801.5 666.5,797 672,797L972,797C977.5,797 982,801.5 982,807C982,812.5 977.5,817 972,817L672,817ZM947,557.8C941.5,557.8 937,553.3 937,547.8C937,542.3 941.5,537.8 947,537.8L972,537.8C977.5,537.8 982,542.3 982,547.8C982,553.3 977.5,557.8 972,557.8L947,557.8ZM922,428.2C916.5,428.2 912,423.7 912,418.2C912,412.6 916.5,408.2 922,408.2L972,408.2C977.5,408.2 982,412.6 982,418.2C982,423.7 977.5,428.2 972,428.2L922,428.2ZM947,493C941.5,493 937,488.5 937,483C937,477.5 941.5,473 947,473L972,473C977.5,473 982,477.5 982,483C982,488.5 977.5,493 972,493L947,493ZM822,363.4C816.5,363.4 812,358.9 812,353.4C812,347.8 816.5,343.4 822,343.4L972,343.4C977.5,343.4 982,347.8 982,353.4C982,358.9 977.5,363.4 972,363.4L822,363.4ZM672,298.5C666.5,298.5 662,294.1 662,288.5C662,283 666.5,278.5 672,278.5L972,278.5C977.5,278.5 982,283 982,288.5C982,294.1 977.5,298.5 972,298.5L672,298.5ZM424,772.6C352.6,754.8 301.9,730.3 266.1,686.8C226.1,638 204.8,565.2 195,450.4C183.3,446.4 141.9,431.7 117.8,418C111.1,414.1 105.7,410.3 102.5,406.8C99.4,403.5 98,400.2 98,397.4C98,394.5 99.3,391.3 102.2,388C105.3,384.4 110.5,380.5 116.9,376.6C139.8,362.5 179.3,347.2 190.4,343.1C197.7,273.6 252.6,220.9 321,197.9C424,163.2 557.3,195.9 601.7,339.2C682.6,362.8 813.4,388.6 905.6,457.8C907,458.8 907.8,460.6 907.6,462.3C887.9,642.7 751.6,737.7 622,771.1C622,780.1 621.9,843.2 620.1,854C616.8,873.8 608.1,880.5 606.3,882C603.7,884.1 598.1,886.6 590.8,888.7C575,893.1 550.3,896.5 530.4,893.9C509,891.2 493.2,881.4 494.7,861.6C496,844.9 501.2,835.7 507.9,830.6C514.7,825.4 523.5,824.2 532.9,824.3C543.2,824.4 554.3,826.2 563.6,823.4C563.8,823.1 564.1,822.5 564.4,821.9C565.2,819.9 565.8,817.2 566.3,814C567.8,804.9 568.3,792.5 568.1,781.6C535.8,785.9 505.2,786.3 478.2,783.2C478.2,804.7 477.8,845.5 476.4,854C473,873.8 464.4,880.5 462.6,882C459.9,884.1 454.4,886.6 447,888.7C431.3,893.1 406.6,896.5 386.6,893.9C365.2,891.2 349.5,881.4 351,861.6C352.3,844.9 357.4,835.7 364.2,830.6C371,825.4 379.8,824.2 389.2,824.3C399.4,824.4 410.6,826.2 419.8,823.4C420,823.1 420.4,822.5 420.6,821.9C421.4,819.9 422,817.2 422.6,814C424.5,802.3 424.7,785 424,772.6ZM430.3,601.4C447.8,619.7 482.9,656.2 517.4,668.7C557.4,683.3 633.5,687.5 671.5,689.6C674.3,689.7 676.7,687.6 676.8,684.9C677,682.1 674.8,679.7 672.1,679.6C634.7,677.6 560.1,673.6 520.8,659.3C487.7,647.3 454.3,612 437.5,594.5C435.6,592.5 432.4,592.4 430.4,594.3C428.4,596.2 428.4,599.4 430.3,601.4ZM491.4,528.7C508.9,547 544,583.5 578.5,596C618.6,610.6 694.6,614.8 732.7,616.9C735.5,617 737.8,614.9 738,612.2C738.1,609.4 736,607.1 733.2,606.9C695.9,604.9 621.2,600.9 581.9,586.6C548.9,574.6 515.4,539.4 498.7,521.8C496.8,519.8 493.6,519.7 491.6,521.6C489.6,523.5 489.5,526.7 491.4,528.7ZM460.9,565.1C478.4,583.4 513.5,619.8 547.9,632.4C588,647 664.1,651.2 702.1,653.2C704.9,653.4 707.2,651.3 707.4,648.5C707.5,645.8 705.4,643.4 702.7,643.3C665.3,641.2 590.6,637.3 551.4,623C518.3,610.9 484.9,575.7 468.1,558.1C466.2,556.1 463,556.1 461,558C459,559.9 459,563.1 460.9,565.1ZM522,492.4C539.5,510.7 574.6,547.1 609.1,559.7C649.1,574.3 725.2,578.5 763.3,580.6C766,580.7 768.4,578.6 768.5,575.8C768.7,573.1 766.6,570.7 763.8,570.6C726.5,568.5 651.8,564.6 612.5,550.3C579.5,538.3 546,503 529.2,485.5C527.3,483.5 524.2,483.4 522.2,485.3C520.2,487.2 520.1,490.4 522,492.4ZM324.1,333.6C308.6,327.7 290.1,338.5 282.6,357.8C275.2,377.2 281.7,397.7 297.1,403.6C312.6,409.6 331.2,398.7 338.6,379.4C346,360.1 339.5,339.6 324.1,333.6Z"
tools:ignore="VectorPath" />
</group>
</vector>

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 658 B

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 443 B

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 879 B

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M16,1L4,1c-1.1,0 -2,0.9 -2,2v14h2L4,3h12L16,1zM19,5L8,5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h11c1.1,0 2,-0.9 2,-2L21,7c0,-1.1 -0.9,-2 -2,-2zM19,21L8,21L8,7h11v14z"/>
</vector>

View File

@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#000000" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM7,13h14v-2L7,11v2zM7,17h14v-2L7,15v2zM7,7v2h14L21,7L7,7z"/>
</vector>

View File

@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
<path android:fillColor="@android:color/white" android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM12,19c-1.66,0 -3,-1.34 -3,-3s1.34,-3 3,-3 3,1.34 3,3 -1.34,3 -3,3zM15,9L5,9L5,5h10v4z"/>
</vector>

View File

@@ -0,0 +1,70 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
xmlns:tools="http://schemas.android.com/tools"
android:width="108dp"
android:height="108dp"
android:viewportWidth="1080"
android:viewportHeight="1080">
<group android:scaleX="0.59325844"
android:scaleY="0.59325844"
android:translateX="222.60674"
android:translateY="219.64044">
<path
android:pathData="M919.5,622.6C914,622.6 909.5,618.1 909.5,612.6C909.5,607.1 914,602.6 919.5,602.6L969.5,602.6C975,602.6 979.5,607.1 979.5,612.6C979.5,618.1 975,622.6 969.5,622.6L919.5,622.6ZM869.5,687.4C864,687.4 859.5,682.9 859.5,677.4C859.5,671.9 864,667.4 869.5,667.4L969.5,667.4C975,667.4 979.5,671.9 979.5,677.4C979.5,682.9 975,687.4 969.5,687.4L869.5,687.4ZM769.5,752.2C764,752.2 759.5,747.7 759.5,742.2C759.5,736.7 764,732.2 769.5,732.2L969.5,732.2C975,732.2 979.5,736.7 979.5,742.2C979.5,747.7 975,752.2 969.5,752.2L769.5,752.2ZM669.5,817C664,817 659.5,812.5 659.5,807C659.5,801.5 664,797 669.5,797L969.5,797C975,797 979.5,801.5 979.5,807C979.5,812.5 975,817 969.5,817L669.5,817ZM944.5,557.8C939,557.8 934.5,553.3 934.5,547.8C934.5,542.2 939,537.8 944.5,537.8L969.5,537.8C975,537.8 979.5,542.2 979.5,547.8C979.5,553.3 975,557.8 969.5,557.8L944.5,557.8ZM919.5,428.1C914,428.1 909.5,423.7 909.5,418.1C909.5,412.6 914,408.1 919.5,408.1L969.5,408.1C975,408.1 979.5,412.6 979.5,418.1C979.5,423.7 975,428.1 969.5,428.1L919.5,428.1ZM944.5,493C939,493 934.5,488.5 934.5,483C934.5,477.4 939,473 944.5,473L969.5,473C975,473 979.5,477.4 979.5,483C979.5,488.5 975,493 969.5,493L944.5,493ZM819.5,363.3C814,363.3 809.5,358.9 809.5,353.3C809.5,347.8 814,343.3 819.5,343.3L969.5,343.3C975,343.3 979.5,347.8 979.5,353.3C979.5,358.9 975,363.3 969.5,363.3L819.5,363.3ZM669.5,298.5C664,298.5 659.5,294 659.5,288.5C659.5,283 664,278.5 669.5,278.5L969.5,278.5C975,278.5 979.5,283 979.5,288.5C979.5,294 975,298.5 969.5,298.5L669.5,298.5Z"
android:fillColor="#018BB3"
tools:ignore="VectorPath" />
<path
android:pathData="M425.1,759.8C428,774.1 428,825.2 419.5,828C394.8,835.9 357.2,813 353.5,862C350.2,904.4 444.1,888.4 456.9,878.1C458.5,876.8 466,870.7 469,853.1C470.8,842.2 470.8,777.1 470.8,770.5"
android:strokeWidth="5.52"
android:fillColor="#FEA01E"
android:strokeColor="#A66101"/>
<path
android:pathData="M568.8,759.8C571.7,774.1 571.8,825.2 563.2,828C538.5,835.9 501,813 497.2,862C494,904.4 587.8,888.4 600.7,878.1C602.3,876.8 609.7,870.7 612.7,853.1C614.5,842.2 614.5,777.1 614.5,770.5"
android:strokeWidth="5.52"
android:fillColor="#FEA01E"
android:strokeColor="#A66101"/>
<path
android:fillColor="#FF000000"
android:pathData="M197.2,446.7C197.2,446.6 100.5,414.6 100.5,397.4C100.5,380.1 192.6,346.7 192.6,346.6C207,174 524.2,106.3 595.2,343.3C675.4,366.9 807.4,392.2 900.1,461.8C871.4,724.7 591.6,803.5 453,774.6C280.3,738.6 216.4,677.2 197.2,446.7Z"/>
<group>
<clip-path
android:pathData="M197.2,446.7C197.2,446.6 100.5,414.6 100.5,397.4C100.5,380.1 192.6,346.7 192.6,346.6C207,174 524.2,106.3 595.2,343.3C675.4,366.9 807.4,392.2 900.1,461.8C871.4,724.7 591.6,803.5 453,774.6C280.3,738.6 216.4,677.2 197.2,446.7Z"/>
<path
android:pathData="M185.6,910.6l-144.1,-700.8l794.1,-163.3l144.1,700.8z">
<aapt:attr name="android:fillColor">
<gradient
android:startX="582.6"
android:startY="829"
android:endX="438.6"
android:endY="128.2"
android:type="linear">
<item android:offset="0" android:color="#FFFFDC82"/>
<item android:offset="0.4" android:color="#FFFEC01C"/>
<item android:offset="1" android:color="#FFFEB902"/>
</gradient>
</aapt:attr>
</path>
<path
android:pathData="M197.2,446.7C197.2,446.6 100.5,414.6 100.5,397.4C100.5,380.1 192.6,346.7 192.6,346.6L197.2,446.7Z"
android:strokeWidth="5.95"
android:fillColor="#FEA01E"
android:strokeColor="#FEA01E"
android:strokeLineCap="butt"/>
</group>
<path
android:pathData="M197.2,446.7C197.2,446.6 100.5,414.6 100.5,397.4C100.5,380.1 192.6,346.7 192.6,346.6C207,174 524.2,106.3 595.2,343.3C675.4,366.9 807.4,392.2 900.1,461.8C871.4,724.7 591.6,803.5 453,774.6C280.3,738.6 216.4,677.2 197.2,446.7Z"
android:strokeWidth="5.95"
android:fillColor="#00000000"
android:strokeColor="#000000"/>
<path
android:pathData="M280.1,357.8a37.5,30 111.1,1 0,56 21.6a37.5,30 111.1,1 0,-56 -21.6z"
android:strokeWidth="3.39"
android:fillColor="#303030"
android:strokeColor="#000000"/>
<path
android:pathData="M523.1,488.9C540.3,506.8 574.5,542.7 608.3,555C648,569.4 723.4,573.5 761,575.5M492.6,525.2C509.7,543.2 544,579 577.7,591.3C617.4,605.8 692.8,609.8 730.5,611.9M462,561.6C479.1,579.5 513.4,615.4 547.2,627.7C586.8,642.1 662.2,646.2 699.9,648.2M431.4,597.9C448.5,615.9 482.8,651.7 516.6,664C556.2,678.5 631.6,682.5 669.3,684.6"
android:strokeWidth="10"
android:fillColor="#00000000"
android:strokeColor="#000000"/>
</group>
</vector>

View File

@@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:width="108dp"
android:height="108dp"
android:viewportWidth="1080"
android:viewportHeight="1080">
<group android:scaleX="0.58666664"
android:scaleY="0.58666664"
android:translateX="223.2"
android:translateY="223.2">
<path
android:fillColor="#FF000000"
android:pathData="M922,622.6C916.5,622.6 912,618.1 912,612.6C912,607.1 916.5,602.6 922,602.6L972,602.6C977.5,602.6 982,607.1 982,612.6C982,618.1 977.5,622.6 972,622.6L922,622.6ZM872,687.4C866.5,687.4 862,682.9 862,677.4C862,671.9 866.5,667.4 872,667.4L972,667.4C977.5,667.4 982,671.9 982,677.4C982,682.9 977.5,687.4 972,687.4L872,687.4ZM772,752.2C766.5,752.2 762,747.7 762,742.2C762,736.7 766.5,732.2 772,732.2L972,732.2C977.5,732.2 982,736.7 982,742.2C982,747.7 977.5,752.2 972,752.2L772,752.2ZM672,817C666.5,817 662,812.5 662,807C662,801.5 666.5,797 672,797L972,797C977.5,797 982,801.5 982,807C982,812.5 977.5,817 972,817L672,817ZM947,557.8C941.5,557.8 937,553.3 937,547.8C937,542.3 941.5,537.8 947,537.8L972,537.8C977.5,537.8 982,542.3 982,547.8C982,553.3 977.5,557.8 972,557.8L947,557.8ZM922,428.2C916.5,428.2 912,423.7 912,418.2C912,412.6 916.5,408.2 922,408.2L972,408.2C977.5,408.2 982,412.6 982,418.2C982,423.7 977.5,428.2 972,428.2L922,428.2ZM947,493C941.5,493 937,488.5 937,483C937,477.5 941.5,473 947,473L972,473C977.5,473 982,477.5 982,483C982,488.5 977.5,493 972,493L947,493ZM822,363.4C816.5,363.4 812,358.9 812,353.4C812,347.8 816.5,343.4 822,343.4L972,343.4C977.5,343.4 982,347.8 982,353.4C982,358.9 977.5,363.4 972,363.4L822,363.4ZM672,298.5C666.5,298.5 662,294.1 662,288.5C662,283 666.5,278.5 672,278.5L972,278.5C977.5,278.5 982,283 982,288.5C982,294.1 977.5,298.5 972,298.5L672,298.5ZM424,772.6C352.6,754.8 301.9,730.3 266.1,686.8C226.1,638 204.8,565.2 195,450.4C183.3,446.4 141.9,431.7 117.8,418C111.1,414.1 105.7,410.3 102.5,406.8C99.4,403.5 98,400.2 98,397.4C98,394.5 99.3,391.3 102.2,388C105.3,384.4 110.5,380.5 116.9,376.6C139.8,362.5 179.3,347.2 190.4,343.1C197.7,273.6 252.6,220.9 321,197.9C424,163.2 557.3,195.9 601.7,339.2C682.6,362.8 813.4,388.6 905.6,457.8C907,458.8 907.8,460.6 907.6,462.3C887.9,642.7 751.6,737.7 622,771.1C622,780.1 621.9,843.2 620.1,854C616.8,873.8 608.1,880.5 606.3,882C603.7,884.1 598.1,886.6 590.8,888.7C575,893.1 550.3,896.5 530.4,893.9C509,891.2 493.2,881.4 494.7,861.6C496,844.9 501.2,835.7 507.9,830.6C514.7,825.4 523.5,824.2 532.9,824.3C543.2,824.4 554.3,826.2 563.6,823.4C563.8,823.1 564.1,822.5 564.4,821.9C565.2,819.9 565.8,817.2 566.3,814C567.8,804.9 568.3,792.5 568.1,781.6C535.8,785.9 505.2,786.3 478.2,783.2C478.2,804.7 477.8,845.5 476.4,854C473,873.8 464.4,880.5 462.6,882C459.9,884.1 454.4,886.6 447,888.7C431.3,893.1 406.6,896.5 386.6,893.9C365.2,891.2 349.5,881.4 351,861.6C352.3,844.9 357.4,835.7 364.2,830.6C371,825.4 379.8,824.2 389.2,824.3C399.4,824.4 410.6,826.2 419.8,823.4C420,823.1 420.4,822.5 420.6,821.9C421.4,819.9 422,817.2 422.6,814C424.5,802.3 424.7,785 424,772.6ZM430.3,601.4C447.8,619.7 482.9,656.2 517.4,668.7C557.4,683.3 633.5,687.5 671.5,689.6C674.3,689.7 676.7,687.6 676.8,684.9C677,682.1 674.8,679.7 672.1,679.6C634.7,677.6 560.1,673.6 520.8,659.3C487.7,647.3 454.3,612 437.5,594.5C435.6,592.5 432.4,592.4 430.4,594.3C428.4,596.2 428.4,599.4 430.3,601.4ZM491.4,528.7C508.9,547 544,583.5 578.5,596C618.6,610.6 694.6,614.8 732.7,616.9C735.5,617 737.8,614.9 738,612.2C738.1,609.4 736,607.1 733.2,606.9C695.9,604.9 621.2,600.9 581.9,586.6C548.9,574.6 515.4,539.4 498.7,521.8C496.8,519.8 493.6,519.7 491.6,521.6C489.6,523.5 489.5,526.7 491.4,528.7ZM460.9,565.1C478.4,583.4 513.5,619.8 547.9,632.4C588,647 664.1,651.2 702.1,653.2C704.9,653.4 707.2,651.3 707.4,648.5C707.5,645.8 705.4,643.4 702.7,643.3C665.3,641.2 590.6,637.3 551.4,623C518.3,610.9 484.9,575.7 468.1,558.1C466.2,556.1 463,556.1 461,558C459,559.9 459,563.1 460.9,565.1ZM522,492.4C539.5,510.7 574.6,547.1 609.1,559.7C649.1,574.3 725.2,578.5 763.3,580.6C766,580.7 768.4,578.6 768.5,575.8C768.7,573.1 766.6,570.7 763.8,570.6C726.5,568.5 651.8,564.6 612.5,550.3C579.5,538.3 546,503 529.2,485.5C527.3,483.5 524.2,483.4 522.2,485.3C520.2,487.2 520.1,490.4 522,492.4ZM324.1,333.6C308.6,327.7 290.1,338.5 282.6,357.8C275.2,377.2 281.7,397.7 297.1,403.6C312.6,409.6 331.2,398.7 338.6,379.4C346,360.1 339.5,339.6 324.1,333.6Z"
tools:ignore="VectorPath" />
</group>
</vector>

View File

@@ -0,0 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:height="24dp" android:viewportHeight="1080" android:viewportWidth="1080" android:width="24dp">
<path android:fillColor="#FF000000" android:pathData="M922,622.6C916.5,622.6 912,618.1 912,612.6C912,607.1 916.5,602.6 922,602.6L972,602.6C977.5,602.6 982,607.1 982,612.6C982,618.1 977.5,622.6 972,622.6L922,622.6ZM872,687.4C866.5,687.4 862,682.9 862,677.4C862,671.9 866.5,667.4 872,667.4L972,667.4C977.5,667.4 982,671.9 982,677.4C982,682.9 977.5,687.4 972,687.4L872,687.4ZM772,752.2C766.5,752.2 762,747.7 762,742.2C762,736.7 766.5,732.2 772,732.2L972,732.2C977.5,732.2 982,736.7 982,742.2C982,747.7 977.5,752.2 972,752.2L772,752.2ZM672,817C666.5,817 662,812.5 662,807C662,801.5 666.5,797 672,797L972,797C977.5,797 982,801.5 982,807C982,812.5 977.5,817 972,817L672,817ZM947,557.8C941.5,557.8 937,553.3 937,547.8C937,542.3 941.5,537.8 947,537.8L972,537.8C977.5,537.8 982,542.3 982,547.8C982,553.3 977.5,557.8 972,557.8L947,557.8ZM922,428.2C916.5,428.2 912,423.7 912,418.2C912,412.6 916.5,408.2 922,408.2L972,408.2C977.5,408.2 982,412.6 982,418.2C982,423.7 977.5,428.2 972,428.2L922,428.2ZM947,493C941.5,493 937,488.5 937,483C937,477.5 941.5,473 947,473L972,473C977.5,473 982,477.5 982,483C982,488.5 977.5,493 972,493L947,493ZM822,363.4C816.5,363.4 812,358.9 812,353.4C812,347.8 816.5,343.4 822,343.4L972,343.4C977.5,343.4 982,347.8 982,353.4C982,358.9 977.5,363.4 972,363.4L822,363.4ZM672,298.5C666.5,298.5 662,294.1 662,288.5C662,283 666.5,278.5 672,278.5L972,278.5C977.5,278.5 982,283 982,288.5C982,294.1 977.5,298.5 972,298.5L672,298.5ZM424,772.6C352.6,754.8 301.9,730.3 266.1,686.8C226.1,638 204.8,565.2 195,450.4C183.3,446.4 141.9,431.7 117.8,418C111.1,414.1 105.7,410.3 102.5,406.8C99.4,403.5 98,400.2 98,397.4C98,394.5 99.3,391.3 102.2,388C105.3,384.4 110.5,380.5 116.9,376.6C139.8,362.5 179.3,347.2 190.4,343.1C197.7,273.6 252.6,220.9 321,197.9C424,163.2 557.3,195.9 601.7,339.2C682.6,362.8 813.4,388.6 905.6,457.8C907,458.8 907.8,460.6 907.6,462.3C887.9,642.7 751.6,737.7 622,771.1C622,780.1 621.9,843.2 620.1,854C616.8,873.8 608.1,880.5 606.3,882C603.7,884.1 598.1,886.6 590.8,888.7C575,893.1 550.3,896.5 530.4,893.9C509,891.2 493.2,881.4 494.7,861.6C496,844.9 501.2,835.7 507.9,830.6C514.7,825.4 523.5,824.2 532.9,824.3C543.2,824.4 554.3,826.2 563.6,823.4C563.8,823.1 564.1,822.5 564.4,821.9C565.2,819.9 565.8,817.2 566.3,814C567.8,804.9 568.3,792.5 568.1,781.6C535.8,785.9 505.2,786.3 478.2,783.2C478.2,804.7 477.8,845.5 476.4,854C473,873.8 464.4,880.5 462.6,882C459.9,884.1 454.4,886.6 447,888.7C431.3,893.1 406.6,896.5 386.6,893.9C365.2,891.2 349.5,881.4 351,861.6C352.3,844.9 357.4,835.7 364.2,830.6C371,825.4 379.8,824.2 389.2,824.3C399.4,824.4 410.6,826.2 419.8,823.4C420,823.1 420.4,822.5 420.6,821.9C421.4,819.9 422,817.2 422.6,814C424.5,802.3 424.7,785 424,772.6ZM430.3,601.4C447.8,619.7 482.9,656.2 517.4,668.7C557.4,683.3 633.5,687.5 671.5,689.6C674.3,689.7 676.7,687.6 676.8,684.9C677,682.1 674.8,679.7 672.1,679.6C634.7,677.6 560.1,673.6 520.8,659.3C487.7,647.3 454.3,612 437.5,594.5C435.6,592.5 432.4,592.4 430.4,594.3C428.4,596.2 428.4,599.4 430.3,601.4ZM491.4,528.7C508.9,547 544,583.5 578.5,596C618.6,610.6 694.6,614.8 732.7,616.9C735.5,617 737.8,614.9 738,612.2C738.1,609.4 736,607.1 733.2,606.9C695.9,604.9 621.2,600.9 581.9,586.6C548.9,574.6 515.4,539.4 498.7,521.8C496.8,519.8 493.6,519.7 491.6,521.6C489.6,523.5 489.5,526.7 491.4,528.7ZM460.9,565.1C478.4,583.4 513.5,619.8 547.9,632.4C588,647 664.1,651.2 702.1,653.2C704.9,653.4 707.2,651.3 707.4,648.5C707.5,645.8 705.4,643.4 702.7,643.3C665.3,641.2 590.6,637.3 551.4,623C518.3,610.9 484.9,575.7 468.1,558.1C466.2,556.1 463,556.1 461,558C459,559.9 459,563.1 460.9,565.1ZM522,492.4C539.5,510.7 574.6,547.1 609.1,559.7C649.1,574.3 725.2,578.5 763.3,580.6C766,580.7 768.4,578.6 768.5,575.8C768.7,573.1 766.6,570.7 763.8,570.6C726.5,568.5 651.8,564.6 612.5,550.3C579.5,538.3 546,503 529.2,485.5C527.3,483.5 524.2,483.4 522.2,485.3C520.2,487.2 520.1,490.4 522,492.4ZM324.1,333.6C308.6,327.7 290.1,338.5 282.6,357.8C275.2,377.2 281.7,397.7 297.1,403.6C312.6,409.6 331.2,398.7 338.6,379.4C346,360.1 339.5,339.6 324.1,333.6Z"
tools:ignore="VectorPath" />
</vector>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
<monochrome android:drawable="@drawable/ic_launcher_monochrome"/>
</adaptive-icon>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
<monochrome android:drawable="@drawable/ic_launcher_monochrome"/>
</adaptive-icon>

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

View File

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#02C5FE</color>
</resources>

View File

@@ -0,0 +1,111 @@
<resources>
<string name="about">About</string>
<string name="about_build">Build: %1$d</string>
<string name="about_netbird_version">NetBird Version</string>
<string name="about_version">JetBird Version: %1$s</string>
<string name="action_not_reversible">This action cannot be undone.</string>
<string name="add_route">Add route</string>
<string name="another_always_on_vpn_active">Another always-on VPN is active</string>
<string name="app">App</string>
<string name="app_name" translatable="false">JetBird</string>
<string name="apps">Apps</string>
<string name="auth_error_see_logs">Authentication error - see logs for more info</string>
<string name="cancel">Cancel</string>
<string name="cidr">CIDR</string>
<string name="clear_log">Clear log</string>
<string name="close">Close</string>
<string name="confirm">Confirm</string>
<string name="connect">Connect</string>
<string name="connect_to_see_peers">Connect to see peers</string>
<string name="connected">Connected</string>
<string name="connecting">Connecting</string>
<string name="copy_log">Copy log</string>
<string name="credits">Credits</string>
<string name="credits_description">See libraries and licenses</string>
<string name="delete">Delete</string>
<string name="disconnect">Disconnect</string>
<string name="disconnected">Disconnected</string>
<string name="dump_netbird_log">Dump NetBird log</string>
<string name="enable_live_logging">Enable live logging</string>
<string name="enable_live_logging_description">See NetBird logs in real time</string>
<string name="enable_logging">Enable logging</string>
<string name="enable_logging_description">See logs from JetBird</string>
<string name="enable_logging_description_netbird">See logs from NetBird</string>
<string name="enable_verbose_logging">Enable verbose logging</string>
<string name="enable_verbose_logging_description">Increase verbosity of JetBird logs</string>
<string name="enable_verbose_logging_description_netbird">Increase verbosity of NetBird logs</string>
<string name="engine_logging_warning">The NetBird client can produce a lot of logs over time.\n\nThese logs are stored in memory and may cause your phone to slow down or JetBird to crash.\n\nYou can also disable live logging and dump the logs afterwards from the log screen.</string>
<string name="example_cidr" translatable="false">192.168.1.0/24</string>
<string name="exclude">Exclude</string>
<string name="exclude_apps">Exclude apps from tunnel</string>
<string name="exclude_apps_description">%1$d apps excluded</string>
<string name="failed_remove_netbird_config">Failed to remove NetBird configuration file</string>
<string name="failed_to_change_management_server">Failed to change management server</string>
<string name="failed_vpn_permission">User rejected VPN permission</string>
<string name="foreground_notification_description">JetBird tunnel is active</string>
<string name="get_started_url">To get started please enter your management server URL</string>
<string name="grant_permission">Grant permission</string>
<string name="log">Log</string>
<string name="log_empty">No log entries</string>
<string name="logging">Logging</string>
<string name="management_server">Management server</string>
<string name="management_url">Management Server URL</string>
<string name="netbird">NetBird</string>
<string name="no_route_overrides">You have no route overrides</string>
<string name="not_set">Not set</string>
<string name="peer_bytes_rx">Bytes RX: %1$sB</string>
<string name="peer_bytes_tx">Bytes TX: %1$sB</string>
<string name="peer_connection_status">Status: %1$s</string>
<string name="peer_connection_status_update">Status last updated: %1$s</string>
<string name="peer_direct">Direct: %1$b</string>
<string name="peer_fqdn">FQDN: %1$s</string>
<string name="peer_info">Peer info</string>
<string name="peer_ip">IP: %1$s</string>
<string name="peer_last_wireguard_handshake">Last WireGuard handshake: %1$s ago</string>
<string name="peer_latency">Latency: %1$dms</string>
<string name="peer_public_key">Public key: %1$s</string>
<string name="peer_relayed">Relayed: %1$b</string>
<string name="peer_rosenpass">Rosenpass: %1$b</string>
<string name="peers_connected">%1$d of %2$d peers connected</string>
<string name="permissive_rosenpass">Permissive Rosenpass</string>
<string name="permissive_rosenpass_description">Allow non-rosenpass peers to connect</string>
<string name="pre_shared_key">Pre-shared key</string>
<string name="removed_netbird_config">Removed NetBird configuration file</string>
<string name="requires_vpn_permission">JetBird needs you to allow it to create a VPN connection on this device.</string>
<string name="reset_app">Reset app</string>
<string name="reset_app_description">Wipe all data and configurations</string>
<string name="reset_netbird_config">Reset NetBird configuration</string>
<string name="reset_netbird_config_description">Remove NetBird configuration file</string>
<string name="reset_to_change_management_server">To change the management server, please reset JetBird</string>
<string name="rosenpass" translatable="false">Rosenpass</string>
<string name="route_calculator">Route calculator</string>
<string name="route_override">Enable route overrides</string>
<string name="route_override_description">Override NetBird routes</string>
<string name="route_selector">Route selector</string>
<string name="route_selector_description">%1$d route overrides</string>
<string name="route_selector_info">Here you can override routes that the NetBird management server sends to you.\n\nWhen enabled, all traffic going to your defined routes will not use the tunnel. You can see all applied routes in the log.\n\nIf you enable route overrides and don\'t provide any routes, JetBird will use upstream routes.</string>
<string name="routes">Routes: %1$s</string>
<string name="save_log">Save log</string>
<string name="settings">Settings</string>
<string name="setup_key">Setup key</string>
<string name="setup_key_saved">Setup key saved</string>
<string name="setup_setup_key_alternative">If you\'d prefer, you can use a setup key instead</string>
<string name="setup_setup_key_required">Please provide a key setup</string>
<string name="setup_sso_supported">Nice! Your server supports SSO!</string>
<string name="setup_sso_unsupported">Your server doesn\'t support SSO :(</string>
<string name="sso_supported">SSO supported</string>
<string name="sso_unsupported">SSO unsupported</string>
<string name="successfully_changed_management_server">Successfully changed management server</string>
<string name="unknown">Unknown</string>
<string name="unknown_error_see_logs">Unknown error - see logs for more info</string>
<string name="upstream_routes">Upstream routes: 0.0.0.0/0, ::/0</string>
<string name="use_setup_key">Use setup key</string>
<string name="use_sso">Use SSO</string>
<string name="view_config">View configuration</string>
<string name="view_config_description">See NetBird configuration file</string>
<string name="view_routes">View routes</string>
<string name="view_routes_description">See calculated tunnel routes</string>
<string name="warning">Warning</string>
<string name="welcome_jetbird">Welcome to JetBird!</string>
<string name="your_overrides">Your overrides: %1$s</string>
</resources>

Some files were not shown because too many files have changed in this diff Show More