Skip to content
Python

Android app: thin wrapper around the web interface (WIP build)

Claude4cf9c99d7c95
diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml
new file mode 100644
index 0000000..7499a33
--- /dev/null
+++ b/.github/workflows/android.yml
@@ -0,0 +1,68 @@
+name: Android app
+
+# Builds the Android app (android/, a thin wrapper around the web interface) as APK.
+# - on pushes that touch android/ (any branch except main) and manually: APK as workflow artifact
+# - from "Image and release" on main: the same build, the release job attaches the APK to the GitHub release
+#
+# Signing: with the repository secrets ANDROID_KEYSTORE_B64 (base64 of the .jks file) and ANDROID_KEYSTORE_PASSWORD
+# (optional ANDROID_KEY_ALIAS, default "mirrorsync"; ANDROID_KEY_PASSWORD, default = keystore password)
+# the APK is signed and named mirrorsync-<version>.apk. Without them it stays unsigned (mirrorsync-<version>-unsigned.apk)
+# and is not attached to releases.
+on:
+ push:
+ branches-ignore: [main]
+ paths: ["android/**", ".github/workflows/android.yml"]
+ workflow_dispatch:
+ workflow_call:
+
+permissions:
+ contents: read
+
+jobs:
+ apk:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: actions/setup-java@v4
+ with:
+ distribution: temurin
+ java-version: "17"
+
+ - uses: gradle/actions/setup-gradle@v4
+
+ - name: Keystore from secrets
+ id: ks
+ env:
+ KS: ${{ secrets.ANDROID_KEYSTORE_B64 }}
+ run: |
+ if [ -n "$KS" ]; then
+ echo "$KS" | base64 -d > "$RUNNER_TEMP/release.jks"
+ echo "path=$RUNNER_TEMP/release.jks" >> "$GITHUB_OUTPUT"
+ fi
+
+ - name: Build APK
+ working-directory: android
+ env:
+ MS_KEYSTORE: ${{ steps.ks.outputs.path }}
+ MS_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
+ MS_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
+ MS_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
+ run: ./gradlew --no-daemon assembleRelease
+
+ - name: Name the APK
+ run: |
+ V=$(tr -d ' \n\r' < app/VERSION)
+ mkdir -p out
+ if [ -f android/app/build/outputs/apk/release/app-release.apk ]; then
+ cp android/app/build/outputs/apk/release/app-release.apk "out/mirrorsync-$V.apk"
+ else
+ cp android/app/build/outputs/apk/release/app-release-unsigned.apk "out/mirrorsync-$V-unsigned.apk"
+ fi
+ ls -l out
+
+ - uses: actions/upload-artifact@v4
+ with:
+ name: mirrorsync-apk
+ path: out/*.apk
+ if-no-files-found: error
diff --git a/android/.gitignore b/android/.gitignore
new file mode 100644
index 0000000..809ba5f
--- /dev/null
+++ b/android/.gitignore
@@ -0,0 +1,7 @@
+.gradle/
+build/
+app/build/
+local.properties
+*.jks
+*.keystore
+keystore.properties
diff --git a/android/app/build.gradle b/android/app/build.gradle
new file mode 100644
index 0000000..f088e0f
--- /dev/null
+++ b/android/app/build.gradle
@@ -0,0 +1,63 @@
+plugins {
+ id "com.android.application"
+}
+
+// The app carries the same version as MirrorSync itself (app/VERSION in the repository root).
+def msVersion = rootProject.file("../app/VERSION").text.trim()
+def (vMajor, vMinor, vPatch) = msVersion.tokenize(".").collect { it.replaceAll("[^0-9]", "").toInteger() }
+
+// Release signing (optional). Either android/keystore.properties (storeFile, storePassword, keyAlias, keyPassword)
+// or the environment variables MS_KEYSTORE, MS_KEYSTORE_PASSWORD, MS_KEY_ALIAS, MS_KEY_PASSWORD.
+// Without them the release APK stays unsigned (app-release-unsigned.apk).
+def ks = new Properties()
+def ksFile = rootProject.file("keystore.properties")
+if (ksFile.exists()) ksFile.withInputStream { ks.load(it) }
+def ksPath = ks.getProperty("storeFile") ?: System.getenv("MS_KEYSTORE")
+
+android {
+ namespace "io.github.dermilderjoghurt.mirrorsync"
+ compileSdk 35
+
+ defaultConfig {
+ applicationId "io.github.dermilderjoghurt.mirrorsync"
+ minSdk 24
+ targetSdk 35
+ versionCode vMajor * 10000 + vMinor * 100 + vPatch
+ versionName msVersion
+ }
+
+ signingConfigs {
+ if (ksPath) {
+ release {
+ storeFile file(ksPath)
+ storePassword ks.getProperty("storePassword") ?: System.getenv("MS_KEYSTORE_PASSWORD")
+ keyAlias ks.getProperty("keyAlias") ?: System.getenv("MS_KEY_ALIAS") ?: "mirrorsync"
+ keyPassword ks.getProperty("keyPassword") ?: System.getenv("MS_KEY_PASSWORD") ?: System.getenv("MS_KEYSTORE_PASSWORD")
+ }
+ }
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled false
+ if (ksPath) signingConfig signingConfigs.release
+ }
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_17
+ }
+
+ buildFeatures {
+ buildConfig true
+ }
+
+ lint {
+ abortOnError false
+ }
+}
+
+dependencies {
+ implementation "androidx.webkit:webkit:1.12.1"
+}
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..92d01bf
--- /dev/null
+++ b/android/app/src/main/AndroidManifest.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <uses-permission android:name="android.permission.INTERNET" />
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="28" />
+
+ <application
+ android:allowBackup="true"
+ android:icon="@mipmap/ic_launcher"
+ android:roundIcon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:networkSecurityConfig="@xml/network_security_config"
+ android:supportsRtl="true"
+ android:theme="@style/AppTheme">
+
+ <activity
+ android:name=".MainActivity"
+ android:exported="true"
+ android:launchMode="singleTask"
+ android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize|keyboardHidden|uiMode|density"
+ android:windowSoftInputMode="adjustResize">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
+ </activity>
+
+ <activity
+ android:name=".SettingsActivity"
+ android:exported="true"
+ android:label="@string/settings_title"
+ android:windowSoftInputMode="adjustResize" />
+
+ <service
+ android:name=".PollService"
+ android:exported="false"
+ android:permission="android.permission.BIND_JOB_SERVICE" />
+
+ <receiver android:name=".BootReceiver" android:exported="false">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
+ </intent-filter>
+ </receiver>
+ </application>
+</manifest>
diff --git a/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/BootReceiver.java b/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/BootReceiver.java
new file mode 100644
index 0000000..f43973d
--- /dev/null
+++ b/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/BootReceiver.java
@@ -0,0 +1,13 @@
+package io.github.dermilderjoghurt.mirrorsync;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+/** Re-plans the background check after a restart of the phone or an update of the app. */
+public class BootReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ PollService.schedule(context);
+ }
+}
diff --git a/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/MainActivity.java b/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/MainActivity.java
new file mode 100644
index 0000000..3585575
--- /dev/null
+++ b/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/MainActivity.java
@@ -0,0 +1,503 @@
+package io.github.dermilderjoghurt.mirrorsync;
+
+import android.Manifest;
+import android.annotation.SuppressLint;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.DownloadManager;
+import android.content.ActivityNotFoundException;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.graphics.Color;
+import android.graphics.Insets;
+import android.net.Uri;
+import android.net.http.SslError;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Environment;
+import android.provider.MediaStore;
+import android.text.InputType;
+import android.util.Base64;
+import android.view.View;
+import android.view.Window;
+import android.view.WindowInsets;
+import android.view.WindowInsetsController;
+import android.webkit.CookieManager;
+import android.webkit.HttpAuthHandler;
+import android.webkit.JavascriptInterface;
+import android.webkit.SslErrorHandler;
+import android.webkit.URLUtil;
+import android.webkit.ValueCallback;
+import android.webkit.WebChromeClient;
+import android.webkit.WebResourceError;
+import android.webkit.WebResourceRequest;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.webkit.WebSettingsCompat;
+import androidx.webkit.WebViewFeature;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import java.util.HashSet;
+import java.util.Set;
+
+/** The MirrorSync web interface in a full-screen WebView. */
+public class MainActivity extends Activity {
+ static final String EXTRA_PATH = "path";
+ static final String EXTRA_RELOAD = "reload";
+ private static final int REQ_FILE = 10;
+ private static final int REQ_NOTIFY = 11;
+
+ private WebView web;
+ private View root;
+ private View error;
+ private TextView errorText;
+ private ProgressBar progress;
+ private ValueCallback<Uri[]> fileCallback;
+ private boolean loadFailed;
+ private final Set<String> trustedCerts = new HashSet<>(); // hosts whose invalid certificate the user accepted (this session)
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ if (Prefs.server(this).isEmpty()) {
+ startActivity(new Intent(this, SettingsActivity.class));
+ finish();
+ return;
+ }
+ setContentView(R.layout.activity_main);
+ root = findViewById(R.id.root);
+ applyInsets(this, root);
+ web = findViewById(R.id.web);
+ error = findViewById(R.id.error);
+ errorText = findViewById(R.id.error_text);
+ progress = findViewById(R.id.progress);
+ findViewById(R.id.retry).setOnClickListener(v -> {
+ error.setVisibility(View.GONE);
+ if (web.getUrl() == null || web.getUrl().startsWith("about:")) web.loadUrl(Prefs.server(this));
+ else web.reload();
+ });
+ findViewById(R.id.change_server).setOnClickListener(v -> startActivity(new Intent(this, SettingsActivity.class)));
+
+ setupWebView();
+ if (savedInstanceState != null) web.restoreState(savedInstanceState);
+ if (web.getUrl() == null) web.loadUrl(startUrl(getIntent()));
+
+ PollService.schedule(this);
+ askNotificationPermission();
+ }
+
+ @SuppressLint("SetJavaScriptEnabled")
+ private void setupWebView() {
+ WebSettings s = web.getSettings();
+ s.setJavaScriptEnabled(true);
+ s.setDomStorageEnabled(true);
+ s.setDatabaseEnabled(true);
+ s.setLoadWithOverviewMode(true);
+ s.setUseWideViewPort(true);
+ s.setSupportZoom(false);
+ s.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
+ s.setUserAgentString(s.getUserAgentString() + " MirrorSyncApp/" + BuildConfig.VERSION_NAME);
+ CookieManager.getInstance().setAcceptCookie(true);
+ CookieManager.getInstance().setAcceptThirdPartyCookies(web, false);
+
+ // Passkeys (WebAuthn). Needs a recent Android System WebView and the Digital Asset Links file
+ // that MirrorSync serves under /.well-known/assetlinks.json.
+ if (WebViewFeature.isFeatureSupported(WebViewFeature.WEB_AUTHENTICATION)) {
+ WebSettingsCompat.setWebAuthenticationSupport(s, WebSettingsCompat.WEB_AUTHENTICATION_SUPPORT_FOR_APP);
+ }
+
+ web.addJavascriptInterface(new Bridge(), "MirrorSyncApp");
+ web.setWebViewClient(new Client());
+ web.setWebChromeClient(new Chrome());
+ web.setDownloadListener((url, ua, disposition, mime, length) -> download(url, ua, disposition, mime));
+ }
+
+ private String startUrl(Intent i) {
+ String base = Prefs.server(this);
+ String path = i == null ? null : i.getStringExtra(EXTRA_PATH);
+ return path != null && path.startsWith("/") ? base + path : base + "/";
+ }
+
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ setIntent(intent);
+ if (web == null) return;
+ if (intent.getBooleanExtra(EXTRA_RELOAD, false)) {
+ web.clearHistory();
+ error.setVisibility(View.GONE);
+ web.loadUrl(startUrl(intent));
+ } else if (intent.getStringExtra(EXTRA_PATH) != null) {
+ web.loadUrl(startUrl(intent));
+ }
+ }
+
+ @Override
+ protected void onSaveInstanceState(Bundle out) {
+ super.onSaveInstanceState(out);
+ if (web != null) web.saveState(out);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (web != null) web.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ if (web != null) web.onPause();
+ CookieManager.getInstance().flush();
+ super.onPause();
+ }
+
+ @Override
+ @SuppressWarnings("deprecation")
+ public void onBackPressed() {
+ if (error.getVisibility() == View.VISIBLE || web == null) {
+ super.onBackPressed();
+ } else if (web.canGoBack()) {
+ web.goBack();
+ } else {
+ new AlertDialog.Builder(this)
+ .setTitle(R.string.exit_title)
+ .setMessage(R.string.exit_text)
+ .setPositiveButton(R.string.exit, (d, w) -> finish())
+ .setNeutralButton(R.string.change_server, (d, w) -> startActivity(new Intent(this, SettingsActivity.class)))
+ .setNegativeButton(R.string.cancel, null)
+ .show();
+ }
+ }
+
+ private void askNotificationPermission() {
+ if (Build.VERSION.SDK_INT < 33 || !Prefs.notifyEnabled(this)) return;
+ if (checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED) return;
+ if (Prefs.get(this).getBoolean(Prefs.KEY_ASKED_PERMISSION, false)) return;
+ Prefs.get(this).edit().putBoolean(Prefs.KEY_ASKED_PERMISSION, true).apply();
+ requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, REQ_NOTIFY);
+ }
+
+ private void showError(String what) {
+ loadFailed = true;
+ errorText.setText(getString(R.string.error_text, Prefs.server(this), what));
+ error.setVisibility(View.VISIBLE);
+ progress.setVisibility(View.GONE);
+ }
+
+ // ------------------------------------------------------------------ insets and colours
+
+ /** Draws edge to edge on every Android version and keeps the content clear of status bar, navigation bar and keyboard. */
+ @SuppressWarnings("deprecation")
+ static void applyInsets(Activity a, View v) {
+ Window w = a.getWindow();
+ w.setStatusBarColor(Color.TRANSPARENT);
+ w.setNavigationBarColor(Color.TRANSPARENT);
+ if (Build.VERSION.SDK_INT >= 30) {
+ w.setDecorFitsSystemWindows(false);
+ } else {
+ v.setSystemUiVisibility(v.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
+ }
+ v.setOnApplyWindowInsetsListener((view, in) -> {
+ if (Build.VERSION.SDK_INT >= 30) {
+ Insets i = in.getInsets(WindowInsets.Type.systemBars() | WindowInsets.Type.ime() | WindowInsets.Type.displayCutout());
+ view.setPadding(i.left, i.top, i.right, i.bottom);
+ return WindowInsets.CONSUMED;
+ }
+ view.setPadding(in.getSystemWindowInsetLeft(), in.getSystemWindowInsetTop(),
+ in.getSystemWindowInsetRight(), in.getSystemWindowInsetBottom());
+ return in.consumeSystemWindowInsets();
+ });
+ v.requestApplyInsets();
+ }
+
+ /** Background behind the system bars follows the page (light/dark theme of the web interface). */
+ @SuppressWarnings("deprecation")
+ private void setBarColor(int color) {
+ root.setBackgroundColor(color);
+ double lum = (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255.0;
+ boolean light = lum > 0.5;
+ if (Build.VERSION.SDK_INT >= 30) {
+ WindowInsetsController c = getWindow().getInsetsController();
+ if (c != null) {
+ int mask = WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS | WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
+ c.setSystemBarsAppearance(light ? mask : 0, mask);
+ }
+ } else {
+ int f = root.getSystemUiVisibility();
+ f = light ? (f | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR) : (f & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
+ if (Build.VERSION.SDK_INT >= 26) {
+ f = light ? (f | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) : (f & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
+ }
+ root.setSystemUiVisibility(f);
+ }
+ }
+
+ // ------------------------------------------------------------------ downloads and uploads
+
+ private void download(String url, String ua, String disposition, String mime) {
+ String name = URLUtil.guessFileName(url, disposition, mime);
+ if (url.startsWith("blob:")) {
+ web.evaluateJavascript("window.__msSaveBlobUrl&&window.__msSaveBlobUrl(" + jsString(url) + "," + jsString(name) + ")", null);
+ return;
+ }
+ if (url.startsWith("data:")) {
+ int comma = url.indexOf(',');
+ if (comma > 0) {
+ String head = url.substring(5, comma);
+ byte[] data = head.endsWith(";base64") ? Base64.decode(url.substring(comma + 1), Base64.DEFAULT)
+ : Uri.decode(url.substring(comma + 1)).getBytes();
+ saveBytes(name, mime, data);
+ }
+ return;
+ }
+ if (Build.VERSION.SDK_INT < 29 && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 12);
+ return;
+ }
+ try {
+ DownloadManager.Request r = new DownloadManager.Request(Uri.parse(url));
+ String cookie = CookieManager.getInstance().getCookie(url);
+ if (cookie != null) r.addRequestHeader("Cookie", cookie);
+ r.addRequestHeader("User-Agent", ua);
+ r.setMimeType(mime);
+ r.setTitle(name);
+ r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
+ r.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, name);
+ ((DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(r);
+ Toast.makeText(this, getString(R.string.download_started, name), Toast.LENGTH_SHORT).show();
+ } catch (Exception e) {
+ Toast.makeText(this, getString(R.string.download_failed, String.valueOf(e.getMessage())), Toast.LENGTH_LONG).show();
+ }
+ }
+
+ /** Writes a file to the public Downloads folder. */
+ private void saveBytes(String name, String mime, byte[] data) {
+ try {
+ if (Build.VERSION.SDK_INT >= 29) {
+ ContentValues cv = new ContentValues();
+ cv.put(MediaStore.Downloads.DISPLAY_NAME, name);
+ cv.put(MediaStore.Downloads.MIME_TYPE, mime == null || mime.isEmpty() ? "application/octet-stream" : mime);
+ Uri uri = getContentResolver().insert(MediaStore.Downloads.EXTERNAL_CONTENT_URI, cv);
+ if (uri == null) throw new IllegalStateException("MediaStore");
+ try (OutputStream out = getContentResolver().openOutputStream(uri)) {
+ if (out == null) throw new IllegalStateException("MediaStore");
+ out.write(data);
+ }
+ } else {
+ if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
+ requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 12);
+ throw new IllegalStateException("permission");
+ }
+ @SuppressWarnings("deprecation")
+ File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
+ //noinspection ResultOfMethodCallIgnored
+ dir.mkdirs();
+ try (OutputStream out = new FileOutputStream(new File(dir, name))) {
+ out.write(data);
+ }
+ }
+ Toast.makeText(this, getString(R.string.download_saved, name), Toast.LENGTH_LONG).show();
+ } catch (Exception e) {
+ Toast.makeText(this, getString(R.string.download_failed, String.valueOf(e.getMessage())), Toast.LENGTH_LONG).show();
+ }
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == REQ_FILE && fileCallback != null) {
+ fileCallback.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, data));
+ fileCallback = null;
+ return;
+ }
+ super.onActivityResult(requestCode, resultCode, data);
+ }
+
+ private static String jsString(String s) {
+ return "'" + s.replace("\\", "\\\\").replace("'", "\\'").replace("\n", "\\n") + "'";
+ }
+
+ /**
+ * Script injected into every page: reports the page colour, saves files that only exist in the page
+ * (blob: links) and turns the POST form of the backup export into a download.
+ */
+ private static final String PAGE_SCRIPT = "(function(){if(window.__msApp)return;window.__msApp=1;"
+ + "function col(){try{MirrorSyncApp.setColor(getComputedStyle(document.body).backgroundColor)}catch(e){}}"
+ + "col();new MutationObserver(col).observe(document.documentElement,{attributes:true,attributeFilter:['data-theme','class']});"
+ + "try{matchMedia('(prefers-color-scheme: dark)').addEventListener('change',col)}catch(e){}"
+ + "function save(blob,name){var r=new FileReader();r.onload=function(){var s=String(r.result);"
+ + "MirrorSyncApp.saveFile(name,blob.type||'application/octet-stream',s.substring(s.indexOf(',')+1))};r.readAsDataURL(blob)}"
+ + "window.__msSaveBlobUrl=function(u,n){fetch(u).then(function(r){return r.blob()}).then(function(b){save(b,n)})};"
+ + "document.addEventListener('submit',function(ev){var f=ev.target;if(!f||!f.action||!/\\/settings\\/backup\\/export$/.test(f.action))return;"
+ + "if(ev.defaultPrevented)return;ev.preventDefault();"
+ + "fetch(f.action,{method:'POST',body:new FormData(f),credentials:'same-origin'}).then(function(r){"
+ + "var cd=r.headers.get('Content-Disposition')||'';if(/attachment/i.test(cd)){"
+ + "var m=/filename\\*?=(?:UTF-8'')?\"?([^\";]+)\"?/i.exec(cd);var n=m?decodeURIComponent(m[1]):'mirrorsync-export.zip';"
+ + "return r.blob().then(function(b){save(b,n)})}"
+ + "return r.text().then(function(t){document.open();document.write(t);document.close()})})},false);"
+ + "})();";
+
+ /** Methods the page can call as window.MirrorSyncApp.* */
+ private class Bridge {
+ @JavascriptInterface
+ public String version() {
+ return BuildConfig.VERSION_NAME;
+ }
+
+ @JavascriptInterface
+ public void saveFile(String name, String mime, String base64) {
+ byte[] data = Base64.decode(base64, Base64.DEFAULT);
+ String safe = name == null || name.isEmpty() ? "download" : name.replaceAll("[\\\\/:*?\"<>|]", "_");
+ runOnUiThread(() -> saveBytes(safe, mime, data));
+ }
+
+ @JavascriptInterface
+ public void setColor(String css) {
+ int c = parseCssColor(css);
+ if (c != 0) runOnUiThread(() -> setBarColor(c));
+ }
+ }
+
+ /** "rgb(9, 9, 11)" / "rgba(…)" → colour int, 0 if not parseable or transparent. */
+ static int parseCssColor(String css) {
+ if (css == null) return 0;
+ java.util.regex.Matcher m = java.util.regex.Pattern
+ .compile("rgba?\\(\\s*(\\d+)[,\\s]+(\\d+)[,\\s]+(\\d+)(?:[,\\s/]+([\\d.]+))?").matcher(css);
+ if (!m.find()) return 0;
+ if (m.group(4) != null && Double.parseDouble(m.group(4)) == 0) return 0;
+ return Color.rgb(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)), Integer.parseInt(m.group(3)));
+ }
+
+ // ------------------------------------------------------------------ WebView callbacks
+
+ private class Client extends WebViewClient {
+ @Override
+ public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
+ Uri u = request.getUrl();
+ String scheme = u.getScheme() == null ? "" : u.getScheme().toLowerCase();
+ if ((scheme.equals("http") || scheme.equals("https")) && Prefs.sameServer(MainActivity.this, u)) return false;
+ try { // other sites (GitHub, docs), mailto: and so on open outside the app
+ startActivity(new Intent(Intent.ACTION_VIEW, u));
+ } catch (ActivityNotFoundException ignored) {
+ // nothing can open it
+ }
+ return true;
+ }
+
+ @Override
+ public void onPageStarted(WebView view, String url, android.graphics.Bitmap favicon) {
+ loadFailed = false;
+ progress.setVisibility(View.VISIBLE);
+ }
+
+ @Override
+ public void onPageFinished(WebView view, String url) {
+ progress.setVisibility(View.GONE);
+ if (!loadFailed) error.setVisibility(View.GONE);
+ CookieManager.getInstance().flush();
+ view.evaluateJavascript(PAGE_SCRIPT, null);
+ }
+
+ @Override
+ public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError err) {
+ if (request.isForMainFrame()) showError(String.valueOf(err.getDescription()));
+ }
+
+ @Override
+ public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError err) {
+ String host = Uri.parse(err.getUrl()).getHost();
+ String key = host + "|" + err.getCertificate().toString();
+ if (trustedCerts.contains(key)) {
+ handler.proceed();
+ return;
+ }
+ int why;
+ switch (err.getPrimaryError()) {
+ case SslError.SSL_EXPIRED:
+ case SslError.SSL_NOTYETVALID:
+ why = R.string.ssl_expired;
+ break;
+ case SslError.SSL_IDMISMATCH:
+ why = R.string.ssl_mismatch;
+ break;
+ case SslError.SSL_UNTRUSTED:
+ why = R.string.ssl_untrusted;
+ break;
+ default:
+ why = R.string.ssl_other;
+ }
+ new AlertDialog.Builder(MainActivity.this)
+ .setTitle(R.string.ssl_title)
+ .setMessage(getString(R.string.ssl_text, host, getString(why)))
+ .setPositiveButton(R.string.ssl_continue, (d, w) -> {
+ trustedCerts.add(key);
+ handler.proceed();
+ })
+ .setNegativeButton(R.string.cancel, (d, w) -> {
+ handler.cancel();
+ showError(getString(R.string.ssl_title));
+ })
+ .setOnCancelListener(d -> {
+ handler.cancel();
+ showError(getString(R.string.ssl_title));
+ })
+ .show();
+ }
+
+ @Override
+ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
+ LinearLayout box = new LinearLayout(MainActivity.this);
+ box.setOrientation(LinearLayout.VERTICAL);
+ int pad = (int) (20 * getResources().getDisplayMetrics().density);
+ box.setPadding(pad, pad / 2, pad, 0);
+ EditText user = new EditText(MainActivity.this);
+ user.setHint(R.string.auth_user);
+ user.setSingleLine(true);
+ EditText pass = new EditText(MainActivity.this);
+ pass.setHint(R.string.auth_pass);
+ pass.setSingleLine(true);
+ pass.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
+ box.addView(user);
+ box.addView(pass);
+ new AlertDialog.Builder(MainActivity.this)
+ .setTitle(getString(R.string.auth_title, host))
+ .setView(box)
+ .setPositiveButton(R.string.login, (d, w) -> handler.proceed(user.getText().toString(), pass.getText().toString()))
+ .setNegativeButton(R.string.cancel, (d, w) -> handler.cancel())
+ .setOnCancelListener(d -> handler.cancel())
+ .show();
+ }
+ }
+
+ private class Chrome extends WebChromeClient {
+ @Override
+ public void onProgressChanged(WebView view, int p) {
+ progress.setProgress(p);
+ progress.setVisibility(p < 100 ? View.VISIBLE : View.GONE);
+ }
+
+ @Override
+ public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> callback, FileChooserParams params) {
+ if (fileCallback != null) fileCallback.onReceiveValue(null);
+ fileCallback = callback;
+ try {
+ startActivityForResult(params.createIntent(), REQ_FILE);
+ } catch (ActivityNotFoundException e) {
+ fileCallback = null;
+ return false;
+ }
+ return true;
+ }
+ }
+}
diff --git a/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/PollService.java b/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/PollService.java
new file mode 100644
index 0000000..ec94740
--- /dev/null
+++ b/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/PollService.java
@@ -0,0 +1,198 @@
+package io.github.dermilderjoghurt.mirrorsync;
+
+import android.Manifest;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.job.JobInfo;
+import android.app.job.JobParameters;
+import android.app.job.JobScheduler;
+import android.app.job.JobService;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.os.Build;
+import android.webkit.CookieManager;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+/**
+ * Background check for notifications: asks MirrorSync for the tasks (GET /api/v1/jobs) and reports every run
+ * that finished since the last check. Uses the API key from the settings or else the login cookie of the app.
+ */
+public class PollService extends JobService {
+ private static final int JOB_ID = 4711;
+ private static final String CH_FAILED = "runs_failed";
+ private static final String CH_DONE = "runs_done";
+ private static final String CH_ACCOUNT = "account";
+ private static final int ID_AUTH = 1;
+
+ static void schedule(Context c) {
+ JobScheduler js = (JobScheduler) c.getSystemService(Context.JOB_SCHEDULER_SERVICE);
+ if (js == null) return;
+ if (!Prefs.notifyEnabled(c) || Prefs.server(c).isEmpty()) {
+ js.cancel(JOB_ID);
+ return;
+ }
+ long period = Prefs.interval(c) * 60_000L;
+ JobInfo existing = js.getPendingJob(JOB_ID);
+ if (existing != null && existing.getIntervalMillis() == period) return;
+ js.schedule(new JobInfo.Builder(JOB_ID, new ComponentName(c, PollService.class))
+ .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY)
+ .setPeriodic(period)
+ .setPersisted(true)
+ .build());
+ }
+
+ @Override
+ public boolean onStartJob(JobParameters params) {
+ String server = Prefs.server(this);
+ String apiKey = Prefs.get(this).getString(Prefs.KEY_API_KEY, "");
+ String cookie = null;
+ try {
+ cookie = CookieManager.getInstance().getCookie(server);
+ } catch (Exception ignored) {
+ // WebView not available (being updated): try again next time
+ }
+ String ck = cookie;
+ new Thread(() -> {
+ try {
+ check(this, server, apiKey, ck);
+ } catch (Exception ignored) {
+ // never crash in the background; the next check tries again
+ }
+ jobFinished(params, false);
+ }).start();
+ return true;
+ }
+
+ @Override
+ public boolean onStopJob(JobParameters params) {
+ return true;
+ }
+
+ static void check(Context c, String server, String apiKey, String cookie) throws Exception {
+ if (server.isEmpty() || !Prefs.notifyEnabled(c)) return;
+ SharedPreferences p = Prefs.get(c);
+ Object[] r = Prefs.httpGet(server + "/api/v1/jobs?lang=" + Prefs.lang(), cookie, apiKey, 20000);
+ int code = (int) r[0];
+ if (code == 401 || code == 403 || (code >= 300 && code < 400)) {
+ if (!p.getBoolean(Prefs.KEY_AUTH_WARNED, false)) {
+ p.edit().putBoolean(Prefs.KEY_AUTH_WARNED, true).apply();
+ notify(c, ID_AUTH, CH_ACCOUNT, c.getString(R.string.n_login_title),
+ c.getString(code == 403 ? R.string.n_perm_text : R.string.n_login_text), null, false);
+ }
+ return;
+ }
+ if (code != 200) return; // server not reachable right now: stay quiet
+ if (p.getBoolean(Prefs.KEY_AUTH_WARNED, false)) {
+ p.edit().putBoolean(Prefs.KEY_AUTH_WARNED, false).apply();
+ cancel(c, ID_AUTH);
+ }
+
+ JSONArray jobs = new JSONArray((String) r[1]);
+ JSONObject seen = new JSONObject(p.getString(Prefs.KEY_SEEN, "{}"));
+ boolean first = !p.contains(Prefs.KEY_SEEN);
+ boolean all = p.getBoolean(Prefs.KEY_NOTIFY_SUCCESS, false);
+ JSONObject now = new JSONObject();
+ for (int i = 0; i < jobs.length(); i++) {
+ JSONObject j = jobs.getJSONObject(i);
+ String id = j.optString("id");
+ String last = j.optString("last_run", "");
+ String status = j.optString("last_status", "");
+ if (id.isEmpty()) continue;
+ if ("laeuft".equals(status)) { // still running: remember the previous run, report when it is done
+ now.put(id, seen.optString(id, last));
+ continue;
+ }
+ now.put(id, last);
+ if (first || last.isEmpty() || !seen.has(id) || last.equals(seen.optString(id))) continue;
+ boolean failed = "fehler".equals(status);
+ if (!failed && !all) continue;
+ report(c, server, apiKey, cookie, id, j.optString("name", id), status);
+ }
+ // tasks that were deleted simply drop out of the map
+ p.edit().putString(Prefs.KEY_SEEN, now.toString()).apply();
+ }
+
+ private static void report(Context c, String server, String apiKey, String cookie, String id, String name, String status) {
+ int title;
+ switch (status) {
+ case "fehler":
+ title = R.string.n_failed;
+ break;
+ case "ok":
+ title = R.string.n_ok;
+ break;
+ case "abgebrochen":
+ title = R.string.n_cancelled;
+ break;
+ default:
+ title = 0;
+ }
+ String head = title != 0 ? c.getString(title, name) : c.getString(R.string.n_other, name, status);
+ String text = "";
+ boolean dry = false;
+ try { // details of the newest run: when, copied, deleted, errors
+ Object[] h = Prefs.httpGet(server + "/api/v1/jobs/" + Uri.encode(id) + "/history?limit=1", cookie, apiKey, 15000);
+ if ((int) h[0] == 200) {
+ JSONArray arr = new JSONArray((String) h[1]);
+ if (arr.length() > 0) {
+ JSONObject e = arr.getJSONObject(0);
+ String start = e.optString("start", "");
+ String when = start.length() >= 16 ? start.substring(11, 16) : start;
+ dry = e.optBoolean("dry_run", false);
+ text = c.getString(R.string.n_details, when, e.optString("copied", "0"), e.optString("deleted", "0"),
+ e.optString("errors", "0"));
+ }
+ }
+ } catch (Exception ignored) {
+ // details are optional
+ }
+ if (dry) head = head + " (" + c.getString(R.string.n_dry) + ")";
+ notify(c, 100 + Math.abs(id.hashCode() % 100000), "fehler".equals(status) ? CH_FAILED : CH_DONE, head, text,
+ "/job/" + Uri.encode(id) + "/log", true);
+ }
+
+ private static void channels(NotificationManager nm, Context c) {
+ if (Build.VERSION.SDK_INT < 26) return;
+ nm.createNotificationChannel(new NotificationChannel(CH_FAILED, c.getString(R.string.ch_failed), NotificationManager.IMPORTANCE_HIGH));
+ nm.createNotificationChannel(new NotificationChannel(CH_DONE, c.getString(R.string.ch_done), NotificationManager.IMPORTANCE_DEFAULT));
+ nm.createNotificationChannel(new NotificationChannel(CH_ACCOUNT, c.getString(R.string.ch_account), NotificationManager.IMPORTANCE_DEFAULT));
+ }
+
+ @SuppressWarnings("deprecation")
+ private static void notify(Context c, int id, String channel, String title, String text, String path, boolean autoCancel) {
+ if (Build.VERSION.SDK_INT >= 33 && c.checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
+ return;
+ }
+ NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
+ if (nm == null) return;
+ channels(nm, c);
+ Intent open = new Intent(c, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ if (path != null) open.putExtra(MainActivity.EXTRA_PATH, path);
+ PendingIntent pi = PendingIntent.getActivity(c, id, open, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
+ Notification.Builder b = Build.VERSION.SDK_INT >= 26 ? new Notification.Builder(c, channel) : new Notification.Builder(c);
+ b.setSmallIcon(R.drawable.ic_notification)
+ .setColor(c.getColor(R.color.brand))
+ .setContentTitle(title)
+ .setContentText(text)
+ .setStyle(new Notification.BigTextStyle().bigText(text))
+ .setContentIntent(pi)
+ .setAutoCancel(autoCancel)
+ .setWhen(System.currentTimeMillis())
+ .setShowWhen(true);
+ if (Build.VERSION.SDK_INT < 26 && CH_FAILED.equals(channel)) b.setPriority(Notification.PRIORITY_HIGH);
+ nm.notify(id, b.build());
+ }
+
+ private static void cancel(Context c, int id) {
+ NotificationManager nm = (NotificationManager) c.getSystemService(Context.NOTIFICATION_SERVICE);
+ if (nm != null) nm.cancel(id);
+ }
+}
diff --git a/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/Prefs.java b/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/Prefs.java
new file mode 100644
index 0000000..543636a
--- /dev/null
+++ b/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/Prefs.java
@@ -0,0 +1,113 @@
+package io.github.dermilderjoghurt.mirrorsync;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.net.Uri;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Locale;
+
+/** Settings of the app and a few small helpers shared by the activities and the background check. */
+final class Prefs {
+ static final String KEY_SERVER = "server_url";
+ static final String KEY_NOTIFY = "notify_enabled";
+ static final String KEY_NOTIFY_SUCCESS = "notify_success";
+ static final String KEY_INTERVAL = "notify_interval_min";
+ static final String KEY_API_KEY = "api_key";
+ static final String KEY_SEEN = "seen_runs";
+ static final String KEY_AUTH_WARNED = "auth_warned";
+ static final String KEY_ASKED_PERMISSION = "asked_notification_permission";
+
+ static final int[] INTERVALS = {15, 30, 60, 180, 360};
+
+ private Prefs() {
+ }
+
+ static SharedPreferences get(Context c) {
+ return c.getSharedPreferences("mirrorsync", Context.MODE_PRIVATE);
+ }
+
+ static String server(Context c) {
+ return get(c).getString(KEY_SERVER, "");
+ }
+
+ static boolean notifyEnabled(Context c) {
+ return get(c).getBoolean(KEY_NOTIFY, true);
+ }
+
+ static int interval(Context c) {
+ return get(c).getInt(KEY_INTERVAL, 15);
+ }
+
+ /** "sync.example.com" → "https://sync.example.com"; removes a trailing slash. Returns "" if unusable. */
+ static String normalize(String raw) {
+ String s = raw == null ? "" : raw.trim();
+ if (s.isEmpty()) return "";
+ if (!s.matches("(?i)^https?://.*")) s = "https://" + s;
+ while (s.endsWith("/")) s = s.substring(0, s.length() - 1);
+ Uri u = Uri.parse(s);
+ if (u.getHost() == null || u.getHost().isEmpty()) return "";
+ return s;
+ }
+
+ static boolean sameServer(Context c, Uri url) {
+ Uri base = Uri.parse(server(c));
+ if (url == null || url.getHost() == null || base.getHost() == null) return false;
+ return url.getHost().equalsIgnoreCase(base.getHost()) && port(url) == port(base);
+ }
+
+ private static int port(Uri u) {
+ if (u.getPort() != -1) return u.getPort();
+ return "http".equalsIgnoreCase(u.getScheme()) ? 80 : 443;
+ }
+
+ static String lang() {
+ String l = Locale.getDefault().getLanguage();
+ return l.matches("de|en|fr|es|it") ? l : "en";
+ }
+
+ /** Small HTTP GET returning {status code, body}. Body is "" on network errors (code -1, message in body). */
+ static Object[] httpGet(String url, String cookie, String apiKey, int timeoutMs) {
+ HttpURLConnection con = null;
+ try {
+ con = (HttpURLConnection) new URL(url).openConnection();
+ con.setConnectTimeout(timeoutMs);
+ con.setReadTimeout(timeoutMs);
+ con.setInstanceFollowRedirects(false);
+ con.setRequestProperty("Accept", "application/json");
+ con.setRequestProperty("Accept-Language", lang());
+ con.setRequestProperty("User-Agent", "MirrorSyncApp/" + BuildConfig.VERSION_NAME);
+ if (apiKey != null && !apiKey.isEmpty()) {
+ con.setRequestProperty("Authorization", "Bearer " + apiKey);
+ } else if (cookie != null && !cookie.isEmpty()) {
+ con.setRequestProperty("Cookie", cookie);
+ }
+ int code = con.getResponseCode();
+ InputStream in = code >= 400 ? con.getErrorStream() : con.getInputStream();
+ return new Object[]{code, in == null ? "" : readAll(in)};
+ } catch (Exception e) {
+ String msg = e.getMessage();
+ return new Object[]{-1, e.getClass().getSimpleName() + (msg == null ? "" : ": " + msg)};
+ } finally {
+ if (con != null) con.disconnect();
+ }
+ }
+
+ static String readAll(InputStream in) throws IOException {
+ try (InputStream is = in) {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ byte[] buf = new byte[8192];
+ int n;
+ while ((n = is.read(buf)) > 0) {
+ out.write(buf, 0, n);
+ if (out.size() > 8 * 1024 * 1024) break;
+ }
+ return out.toString(StandardCharsets.UTF_8.name());
+ }
+ }
+}
diff --git a/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/SettingsActivity.java b/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/SettingsActivity.java
new file mode 100644
index 0000000..b6a0518
--- /dev/null
+++ b/android/app/src/main/java/io/github/dermilderjoghurt/mirrorsync/SettingsActivity.java
@@ -0,0 +1,169 @@
+package io.github.dermilderjoghurt.mirrorsync;
+
+import android.Manifest;
+import android.app.Activity;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.view.View;
+import android.view.inputmethod.EditorInfo;
+import android.widget.ArrayAdapter;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.Spinner;
+import android.widget.Switch;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import org.json.JSONObject;
+
+/** First start: enter the server address. Later: change the address and the notification settings. */
+public class SettingsActivity extends Activity {
+ private EditText url;
+ private EditText apiKey;
+ private TextView status;
+ private Button connect;
+ private Switch notify;
+ private Switch notifySuccess;
+ private Spinner interval;
+ private boolean firstRun;
+ private String failedUrl; // address that failed the check; a second tap saves it anyway
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_settings);
+ MainActivity.applyInsets(this, findViewById(R.id.root));
+ SharedPreferences p = Prefs.get(this);
+ firstRun = Prefs.server(this).isEmpty();
+
+ url = findViewById(R.id.url);
+ apiKey = findViewById(R.id.api_key);
+ status = findViewById(R.id.status);
+ connect = findViewById(firstRun ? R.id.connect : R.id.save); // the button that checks and saves
+ notify = findViewById(R.id.notify);
+ notifySuccess = findViewById(R.id.notify_success);
+ interval = findViewById(R.id.interval);
+
+ url.setText(Prefs.server(this));
+ apiKey.setText(p.getString(Prefs.KEY_API_KEY, ""));
+ notify.setChecked(Prefs.notifyEnabled(this));
+ notifySuccess.setChecked(p.getBoolean(Prefs.KEY_NOTIFY_SUCCESS, false));
+ notifySuccess.setEnabled(notify.isChecked());
+ notify.setOnCheckedChangeListener((b, on) -> notifySuccess.setEnabled(on));
+
+ String[] labels = new String[Prefs.INTERVALS.length];
+ int sel = 0;
+ for (int i = 0; i < Prefs.INTERVALS.length; i++) {
+ int m = Prefs.INTERVALS[i];
+ labels[i] = m < 60 ? getString(R.string.minutes, m) : (m == 60 ? getString(R.string.hour) : getString(R.string.hours, m / 60));
+ if (m == Prefs.interval(this)) sel = i;
+ }
+ ArrayAdapter<String> ad = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, labels);
+ ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ interval.setAdapter(ad);
+ interval.setSelection(sel);
+
+ ((TextView) findViewById(R.id.version)).setText(getString(R.string.version_info, BuildConfig.VERSION_NAME));
+ if (!firstRun) findViewById(R.id.welcome).setVisibility(View.GONE);
+ if (!firstRun) ((TextView) findViewById(R.id.title)).setText(R.string.settings_title);
+ findViewById(R.id.connect).setVisibility(firstRun ? View.VISIBLE : View.GONE);
+ findViewById(R.id.save).setVisibility(firstRun ? View.GONE : View.VISIBLE);
+ connect.setOnClickListener(v -> check());
+ url.setOnEditorActionListener((v, id, e) -> {
+ if (id == EditorInfo.IME_ACTION_GO) {
+ check();
+ return true;
+ }
+ return false;
+ });
+ }
+
+ /** Checks /health of the entered address, then saves. */
+ private void check() {
+ String u = Prefs.normalize(url.getText().toString());
+ if (u.isEmpty()) {
+ showStatus(getString(R.string.url_invalid), false);
+ return;
+ }
+ url.setText(u);
+ if (u.equals(failedUrl) || u.equals(Prefs.server(this))) {
+ save(u);
+ return;
+ }
+ showStatus(getString(R.string.checking), true);
+ connect.setEnabled(false);
+ new Thread(() -> {
+ Object[] r = Prefs.httpGet(u + "/health", null, null, 10000);
+ String version = null;
+ String problem;
+ int code = (int) r[0];
+ if (code == 200) {
+ try {
+ JSONObject o = new JSONObject((String) r[1]);
+ if ("ok".equals(o.optString("status"))) version = o.optString("version", "?");
+ } catch (Exception ignored) {
+ // not JSON: some other web server
+ }
+ problem = "HTTP 200, " + getString(R.string.app_name) + "?";
+ } else {
+ problem = code == -1 ? (String) r[1] : "HTTP " + code;
+ }
+ String v = version;
+ runOnUiThread(() -> {
+ connect.setEnabled(true);
+ if (v != null) {
+ showStatus(getString(R.string.check_ok, v), true);
+ save(u);
+ } else {
+ failedUrl = u;
+ showStatus(getString(R.string.check_fail, problem) + "\n" + getString(R.string.check_fail_hint), false);
+ connect.setText(R.string.save_anyway);
+ }
+ });
+ }).start();
+ }
+
+ private void save(String u) {
+ boolean changed = !u.equals(Prefs.server(this));
+ int min = Prefs.INTERVALS[Math.max(0, interval.getSelectedItemPosition())];
+ SharedPreferences.Editor e = Prefs.get(this).edit()
+ .putString(Prefs.KEY_SERVER, u)
+ .putBoolean(Prefs.KEY_NOTIFY, notify.isChecked())
+ .putBoolean(Prefs.KEY_NOTIFY_SUCCESS, notifySuccess.isChecked())
+ .putInt(Prefs.KEY_INTERVAL, min)
+ .putString(Prefs.KEY_API_KEY, apiKey.getText().toString().trim())
+ .putBoolean(Prefs.KEY_AUTH_WARNED, false);
+ if (changed) e.remove(Prefs.KEY_SEEN); // other server: start fresh, no flood of old runs
+ e.apply();
+ PollService.schedule(this);
+ if (notify.isChecked() && Build.VERSION.SDK_INT >= 33
+ && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
+ requestPermissions(new String[]{Manifest.permission.POST_NOTIFICATIONS}, 1);
+ return; // continue in onRequestPermissionsResult
+ }
+ done(changed);
+ }
+
+ @Override
+ public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
+ done(true);
+ }
+
+ private void done(boolean changed) {
+ Toast.makeText(this, R.string.saved, Toast.LENGTH_SHORT).show();
+ Intent i = new Intent(this, MainActivity.class);
+ i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
+ if (changed) i.putExtra(MainActivity.EXTRA_RELOAD, true);
+ startActivity(i);
+ finish();
+ }
+
+ private void showStatus(String text, boolean ok) {
+ status.setVisibility(View.VISIBLE);
+ status.setText(text);
+ status.setTextColor(ok ? getColor(R.color.muted) : 0xFFDC2626);
+ }
+}
diff --git a/android/app/src/main/res/drawable/ic_launcher_background.xml b/android/app/src/main/res/drawable/ic_launcher_background.xml
new file mode 100644
index 0000000..041ff3b
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_launcher_background.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:aapt="http://schemas.android.com/aapt"
+ android:width="108dp" android:height="108dp" android:viewportWidth="108" android:viewportHeight="108">
+ <path android:pathData="M0,0h108v108h-108z">
+ <aapt:attr name="android:fillColor">
+ <gradient android:type="linear" android:startX="0" android:startY="0" android:endX="108" android:endY="108"
+ android:startColor="#4F46E5" android:endColor="#A855F7" />
+ </aapt:attr>
+ </path>
+</vector>
diff --git a/android/app/src/main/res/drawable/ic_launcher_foreground.xml b/android/app/src/main/res/drawable/ic_launcher_foreground.xml
new file mode 100644
index 0000000..b2ba069
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_launcher_foreground.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- The two sync arrows of the MirrorSync logo (app/static/favicon.svg), centred in the 66 dp safe zone. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="108dp" android:height="108dp" android:viewportWidth="108" android:viewportHeight="108">
+ <group android:translateX="30" android:translateY="30" android:scaleX="2" android:scaleY="2">
+ <path android:pathData="M21,12a9,9 0,0 1,-15.5,6.2L3,16" android:strokeColor="#FFFFFF" android:strokeWidth="2.4" android:strokeLineCap="round" android:strokeLineJoin="round" />
+ <path android:pathData="M3,12a9,9 0,0 1,15.5,-6.2L21,8" android:strokeColor="#FFFFFF" android:strokeWidth="2.4" android:strokeLineCap="round" android:strokeLineJoin="round" />
+ <path android:pathData="M21,3v5h-5" android:strokeColor="#FFFFFF" android:strokeWidth="2.4" android:strokeLineCap="round" android:strokeLineJoin="round" />
+ <path android:pathData="M3,21v-5h5" android:strokeColor="#FFFFFF" android:strokeWidth="2.4" android:strokeLineCap="round" android:strokeLineJoin="round" />
+ </group>
+</vector>
diff --git a/android/app/src/main/res/drawable/ic_notification.xml b/android/app/src/main/res/drawable/ic_notification.xml
new file mode 100644
index 0000000..ba43994
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_notification.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp" android:height="24dp" android:viewportWidth="24" android:viewportHeight="24">
+ <group android:pivotX="12" android:pivotY="12" android:scaleX="0.9" android:scaleY="0.9">
+ <path android:pathData="M21,12a9,9 0,0 1,-15.5,6.2L3,16" android:strokeColor="#FFFFFF" android:strokeWidth="2.4" android:strokeLineCap="round" android:strokeLineJoin="round" />
+ <path android:pathData="M3,12a9,9 0,0 1,15.5,-6.2L21,8" android:strokeColor="#FFFFFF" android:strokeWidth="2.4" android:strokeLineCap="round" android:strokeLineJoin="round" />
+ <path android:pathData="M21,3v5h-5" android:strokeColor="#FFFFFF" android:strokeWidth="2.4" android:strokeLineCap="round" android:strokeLineJoin="round" />
+ <path android:pathData="M3,21v-5h5" android:strokeColor="#FFFFFF" android:strokeWidth="2.4" android:strokeLineCap="round" android:strokeLineJoin="round" />
+ </group>
+</vector>
diff --git a/android/app/src/main/res/drawable/ic_shortcut_settings.xml b/android/app/src/main/res/drawable/ic_shortcut_settings.xml
new file mode 100644
index 0000000..6c0e9fb
--- /dev/null
+++ b/android/app/src/main/res/drawable/ic_shortcut_settings.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="48dp" android:height="48dp" android:viewportWidth="48" android:viewportHeight="48">
+ <path android:fillColor="#4F46E5" android:pathData="M24,0a24,24 0,1 1,0,48a24,24 0,1 1,0,-48z" />
+ <group android:translateX="12" android:translateY="12">
+ <path android:fillColor="#FFFFFF" android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z" />
+ </group>
+</vector>
diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..7f69db2
--- /dev/null
+++ b/android/app/src/main/res/layout/activity_main.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/bg">
+
+ <WebView
+ android:id="@+id/web"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" />
+
+ <ProgressBar
+ android:id="@+id/progress"
+ style="@android:style/Widget.Material.ProgressBar.Horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="3dp"
+ android:indeterminate="false"
+ android:max="100"
+ android:progressTint="@color/brand"
+ android:visibility="gone" />
+
+ <LinearLayout
+ android:id="@+id/error"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@color/bg"
+ android:gravity="center"
+ android:orientation="vertical"
+ android:padding="32dp"
+ android:visibility="gone">
+
+ <ImageView
+ android:layout_width="72dp"
+ android:layout_height="72dp"
+ android:contentDescription="@string/app_name"
+ android:src="@mipmap/ic_launcher" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:gravity="center"
+ android:text="@string/error_title"
+ android:textColor="@color/fg"
+ android:textSize="20sp"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/error_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"
+ android:gravity="center"
+ android:textColor="@color/muted"
+ android:textSize="14sp" />
+
+ <Button
+ android:id="@+id/retry"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="24dp"
+ android:minWidth="200dp"
+ android:text="@string/retry" />
+
+ <Button
+ android:id="@+id/change_server"
+ style="@android:style/Widget.Material.Button.Borderless.Colored"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:minWidth="200dp"
+ android:text="@string/change_server" />
+ </LinearLayout>
+</FrameLayout>
diff --git a/android/app/src/main/res/layout/activity_settings.xml b/android/app/src/main/res/layout/activity_settings.xml
new file mode 100644
index 0000000..36ade52
--- /dev/null
+++ b/android/app/src/main/res/layout/activity_settings.xml
@@ -0,0 +1,154 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:fillViewport="true">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:padding="24dp">
+
+ <ImageView
+ android:layout_width="72dp"
+ android:layout_height="72dp"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginTop="16dp"
+ android:contentDescription="@string/app_name"
+ android:src="@mipmap/ic_launcher" />
+
+ <TextView
+ android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="12dp"
+ android:gravity="center_horizontal"
+ android:text="@string/app_name"
+ android:textColor="@color/fg"
+ android:textSize="24sp"
+ android:textStyle="bold" />
+
+ <TextView
+ android:id="@+id/welcome"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"
+ android:gravity="center_horizontal"
+ android:text="@string/welcome"
+ android:textColor="@color/muted"
+ android:textSize="15sp" />
+
+ <TextView
+ style="@style/Label"
+ android:text="@string/server_url" />
+
+ <EditText
+ android:id="@+id/url"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/server_hint"
+ android:importantForAutofill="no"
+ android:inputType="textUri"
+ android:imeOptions="actionGo"
+ android:singleLine="true"
+ android:textColor="@color/fg" />
+
+ <TextView
+ android:id="@+id/status"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="4dp"
+ android:textSize="14sp"
+ android:visibility="gone" />
+
+ <Button
+ android:id="@+id/connect"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="12dp"
+ android:text="@string/connect" />
+
+ <TextView
+ style="@style/Label"
+ android:layout_marginTop="32dp"
+ android:text="@string/notifications"
+ android:textSize="18sp" />
+
+ <Switch
+ android:id="@+id/notify"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"
+ android:minHeight="48dp"
+ android:text="@string/notify_enabled"
+ android:textColor="@color/fg"
+ android:textSize="15sp" />
+
+ <Switch
+ android:id="@+id/notify_success"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:minHeight="48dp"
+ android:text="@string/notify_success"
+ android:textColor="@color/fg"
+ android:textSize="15sp" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical"
+ android:minHeight="48dp"
+ android:orientation="horizontal">
+
+ <TextView
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="@string/notify_interval"
+ android:textColor="@color/fg"
+ android:textSize="15sp" />
+
+ <Spinner
+ android:id="@+id/interval"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content" />
+ </LinearLayout>
+
+ <TextView
+ style="@style/Hint"
+ android:text="@string/notify_info" />
+
+ <TextView
+ style="@style/Label"
+ android:text="@string/api_key" />
+
+ <EditText
+ android:id="@+id/api_key"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/api_key_hint"
+ android:importantForAutofill="no"
+ android:inputType="textPassword"
+ android:singleLine="true"
+ android:textColor="@color/fg" />
+
+ <TextView
+ style="@style/Hint"
+ android:text="@string/api_key_info" />
+
+ <Button
+ android:id="@+id/save"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="24dp"
+ android:text="@string/save" />
+
+ <TextView
+ android:id="@+id/version"
+ style="@style/Hint"
+ android:layout_marginTop="24dp"
+ android:gravity="center_horizontal" />
+ </LinearLayout>
+</ScrollView>
diff --git a/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 0000000..b3e26b4
--- /dev/null
+++ b/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -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="@drawable/ic_launcher_background" />
+ <foreground android:drawable="@drawable/ic_launcher_foreground" />
+ <monochrome android:drawable="@drawable/ic_launcher_foreground" />
+</adaptive-icon>
diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
new file mode 100644
index 0000000..5b441b6
Binary files /dev/null and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
new file mode 100644
index 0000000..d993820
Binary files /dev/null and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
new file mode 100644
index 0000000..74be8cd
Binary files /dev/null and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
new file mode 100644
index 0000000..e4f2cff
Binary files /dev/null and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
new file mode 100644
index 0000000..70981fd
Binary files /dev/null and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ
diff --git a/android/app/src/main/res/values-de/strings.xml b/android/app/src/main/res/values-de/strings.xml
new file mode 100644
index 0000000..d3ca3df
--- /dev/null
+++ b/android/app/src/main/res/values-de/strings.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="settings_title">Server &amp; Benachrichtigungen</string>
+ <string name="welcome">Gib die Adresse deines MirrorSync-Servers ein, also die, die du auch im Browser öffnest.</string>
+ <string name="server_url">Server-Adresse</string>
+ <string name="connect">Verbinden</string>
+ <string name="save_anyway">Trotzdem speichern</string>
+ <string name="checking">Verbindung wird geprüft …</string>
+ <string name="check_ok">Verbunden mit MirrorSync %1$s.</string>
+ <string name="check_fail">Unter dieser Adresse wurde kein MirrorSync gefunden: %1$s</string>
+ <string name="check_fail_hint">Prüfe die Adresse (http oder https, Port). Speichern geht trotzdem.</string>
+ <string name="url_invalid">Bitte eine Adresse eingeben, z. B. https://sync.example.com oder http://192.168.1.10:8080.</string>
+ <string name="notifications">Benachrichtigungen</string>
+ <string name="notify_enabled">Bei fehlgeschlagenen Läufen benachrichtigen</string>
+ <string name="notify_success">Auch erfolgreiche und abgebrochene Läufe melden</string>
+ <string name="notify_interval">Prüfen alle</string>
+ <string name="notify_info">Die App fragt MirrorSync im Hintergrund nach neuen Ergebnissen. Den genauen Zeitpunkt bestimmt Android, eine Meldung kann also ein paar Minuten später kommen.</string>
+ <string name="api_key">API-Key (optional)</string>
+ <string name="api_key_info">Ohne Key nutzt die App deine Anmeldung aus der App. Eine Anmeldung ohne „Angemeldet bleiben“ kann enden, wenn die App geschlossen wird, danach kommen keine Meldungen mehr. Ein API-Key mit einer Rolle, die Aufgaben sehen darf, verhindert das (in MirrorSync unter Einstellungen → API).</string>
+ <string name="save">Speichern</string>
+ <string name="saved">Gespeichert.</string>
+ <string name="open_app">MirrorSync öffnen</string>
+ <string name="version_info">App-Version %1$s</string>
+ <string name="minutes">%1$d Minuten</string>
+ <string name="hour">1 Stunde</string>
+ <string name="hours">%1$d Stunden</string>
+
+ <string name="error_title">MirrorSync ist nicht erreichbar</string>
+ <string name="retry">Erneut versuchen</string>
+ <string name="change_server">Server ändern</string>
+ <string name="exit_text">App schließen oder Server-Adresse ändern?</string>
+ <string name="exit">Schließen</string>
+ <string name="cancel">Abbrechen</string>
+ <string name="reload">Neu laden</string>
+ <string name="ssl_title">Zertifikat nicht vertrauenswürdig</string>
+ <string name="ssl_text">Das Zertifikat von %1$s ist ungültig (%2$s). Fahre nur fort, wenn das dein eigener Server mit selbst erstelltem Zertifikat ist.</string>
+ <string name="ssl_continue">Trotzdem fortfahren</string>
+ <string name="ssl_expired">abgelaufen</string>
+ <string name="ssl_mismatch">für einen anderen Namen ausgestellt</string>
+ <string name="ssl_untrusted">unbekannter Aussteller</string>
+ <string name="ssl_other">ungültig</string>
+ <string name="auth_title">Anmeldung für %1$s</string>
+ <string name="auth_user">Benutzername</string>
+ <string name="auth_pass">Passwort</string>
+ <string name="login">Anmelden</string>
+ <string name="download_started">Download gestartet: %1$s</string>
+ <string name="download_saved">In Downloads gespeichert: %1$s</string>
+ <string name="download_failed">Download fehlgeschlagen: %1$s</string>
+
+ <string name="ch_failed">Fehlgeschlagene Läufe</string>
+ <string name="ch_done">Abgeschlossene Läufe</string>
+ <string name="ch_account">Verbindung</string>
+ <string name="n_failed">%1$s fehlgeschlagen</string>
+ <string name="n_ok">%1$s abgeschlossen</string>
+ <string name="n_cancelled">%1$s abgebrochen</string>
+ <string name="n_details">%1$s · kopiert %2$s · gelöscht %3$s · Fehler %4$s</string>
+ <string name="n_dry">Testlauf</string>
+ <string name="n_login_title">Benachrichtigungen pausiert</string>
+ <string name="n_login_text">MirrorSync nimmt die Anmeldung der App nicht mehr an. Öffne die App und melde dich neu an, oder trage einen API-Key ein.</string>
+ <string name="n_perm_text">Der API-Key oder dein Benutzer darf keine Aufgaben sehen.</string>
+</resources>
diff --git a/android/app/src/main/res/values-night/colors.xml b/android/app/src/main/res/values-night/colors.xml
new file mode 100644
index 0000000..f286e5a
--- /dev/null
+++ b/android/app/src/main/res/values-night/colors.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <color name="bg">#09090b</color>
+ <color name="fg">#e7e9f0</color>
+ <color name="muted">#9aa1b2</color>
+</resources>
diff --git a/android/app/src/main/res/values-night/themes.xml b/android/app/src/main/res/values-night/themes.xml
new file mode 100644
index 0000000..154f550
--- /dev/null
+++ b/android/app/src/main/res/values-night/themes.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="AppTheme" parent="android:Theme.Material.NoActionBar">
+ <item name="android:colorPrimary">#6d5cf0</item>
+ <item name="android:colorPrimaryDark">#3730a3</item>
+ <item name="android:colorAccent">#8b7cf6</item>
+ <item name="android:windowBackground">@color/bg</item>
+ <item name="android:statusBarColor">@color/bg</item>
+ <item name="android:navigationBarColor">@color/bg</item>
+ <item name="android:windowLightStatusBar">false</item>
+ </style>
+</resources>
diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml
new file mode 100644
index 0000000..5a5d036
--- /dev/null
+++ b/android/app/src/main/res/values/colors.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <color name="bg">#f6f7f9</color>
+ <color name="fg">#1f2330</color>
+ <color name="muted">#6b7280</color>
+ <color name="brand">#4f46e5</color>
+ <color name="brand2">#a855f7</color>
+</resources>
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
new file mode 100644
index 0000000..17321cc
--- /dev/null
+++ b/android/app/src/main/res/values/strings.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">MirrorSync</string>
+ <string name="settings_title">Server &amp; notifications</string>
+ <string name="welcome">Enter the address of your MirrorSync server, the same one you open in the browser.</string>
+ <string name="server_url">Server address</string>
+ <string name="server_hint">https://sync.example.com</string>
+ <string name="connect">Connect</string>
+ <string name="save_anyway">Save anyway</string>
+ <string name="checking">Checking connection…</string>
+ <string name="check_ok">Connected to MirrorSync %1$s.</string>
+ <string name="check_fail">No MirrorSync found at this address: %1$s</string>
+ <string name="check_fail_hint">Check the address (http or https, port). You can still save it.</string>
+ <string name="url_invalid">Please enter an address, e.g. https://sync.example.com or http://192.168.1.10:8080.</string>
+ <string name="notifications">Notifications</string>
+ <string name="notify_enabled">Notify me about failed runs</string>
+ <string name="notify_success">Also notify about successful and cancelled runs</string>
+ <string name="notify_interval">Check every</string>
+ <string name="notify_info">The app asks MirrorSync for new results in the background. Android decides the exact time, so a message can arrive a few minutes late.</string>
+ <string name="api_key">API key (optional)</string>
+ <string name="api_key_hint">msk_…</string>
+ <string name="api_key_info">Without a key the app uses your login from the app. A login without \"Stay signed in\" can end when the app is closed, then no notifications arrive. An API key with a role that may view tasks avoids this (Settings → API in MirrorSync).</string>
+ <string name="save">Save</string>
+ <string name="saved">Saved.</string>
+ <string name="open_app">Open MirrorSync</string>
+ <string name="version_info">App version %1$s</string>
+ <string name="minutes">%1$d minutes</string>
+ <string name="hour">1 hour</string>
+ <string name="hours">%1$d hours</string>
+
+ <string name="error_title">MirrorSync cannot be reached</string>
+ <string name="error_text">%1$s\n\n%2$s</string>
+ <string name="retry">Try again</string>
+ <string name="change_server">Change server</string>
+ <string name="exit_title">MirrorSync</string>
+ <string name="exit_text">Close the app or change the server address?</string>
+ <string name="exit">Close</string>
+ <string name="cancel">Cancel</string>
+ <string name="reload">Reload</string>
+ <string name="ssl_title">Certificate not trusted</string>
+ <string name="ssl_text">The certificate of %1$s is not valid (%2$s). Only continue if this is your own server with a self-signed certificate.</string>
+ <string name="ssl_continue">Continue anyway</string>
+ <string name="ssl_expired">expired</string>
+ <string name="ssl_mismatch">issued for another name</string>
+ <string name="ssl_untrusted">unknown issuer</string>
+ <string name="ssl_other">invalid</string>
+ <string name="auth_title">Login for %1$s</string>
+ <string name="auth_user">User name</string>
+ <string name="auth_pass">Password</string>
+ <string name="login">Log in</string>
+ <string name="download_started">Download started: %1$s</string>
+ <string name="download_saved">Saved to Downloads: %1$s</string>
+ <string name="download_failed">Download failed: %1$s</string>
+
+ <string name="ch_failed">Failed runs</string>
+ <string name="ch_done">Finished runs</string>
+ <string name="ch_account">Connection</string>
+ <string name="n_failed">%1$s failed</string>
+ <string name="n_ok">%1$s finished</string>
+ <string name="n_cancelled">%1$s cancelled</string>
+ <string name="n_other">%1$s: %2$s</string>
+ <string name="n_details">%1$s · copied %2$s · deleted %3$s · errors %4$s</string>
+ <string name="n_dry">Test run</string>
+ <string name="n_login_title">Notifications paused</string>
+ <string name="n_login_text">MirrorSync no longer accepts the login of the app. Open the app and log in again, or enter an API key.</string>
+ <string name="n_perm_text">The API key or your user may not view tasks.</string>
+</resources>
diff --git a/android/app/src/main/res/values/styles.xml b/android/app/src/main/res/values/styles.xml
new file mode 100644
index 0000000..05b08da
--- /dev/null
+++ b/android/app/src/main/res/values/styles.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="Label">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:layout_marginTop">20dp</item>
+ <item name="android:textColor">@color/fg</item>
+ <item name="android:textSize">15sp</item>
+ <item name="android:textStyle">bold</item>
+ </style>
+ <style name="Hint">
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:layout_marginTop">4dp</item>
+ <item name="android:textColor">@color/muted</item>
+ <item name="android:textSize">13sp</item>
+ </style>
+</resources>
diff --git a/android/app/src/main/res/values/themes.xml b/android/app/src/main/res/values/themes.xml
new file mode 100644
index 0000000..5acd8d1
--- /dev/null
+++ b/android/app/src/main/res/values/themes.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
+ <item name="android:colorPrimary">#4f46e5</item>
+ <item name="android:colorPrimaryDark">#3730a3</item>
+ <item name="android:colorAccent">#6d5cf0</item>
+ <item name="android:windowBackground">@color/bg</item>
+ <item name="android:statusBarColor">@color/bg</item>
+ <item name="android:navigationBarColor">@color/bg</item>
+ <item name="android:windowLightStatusBar">true</item>
+ </style>
+</resources>
diff --git a/android/app/src/main/res/xml/network_security_config.xml b/android/app/src/main/res/xml/network_security_config.xml
new file mode 100644
index 0000000..0273a5b
--- /dev/null
+++ b/android/app/src/main/res/xml/network_security_config.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- MirrorSync often runs in the home network without HTTPS (http://192.168.x.x:8080), so plain HTTP is allowed.
+ User-installed CA certificates are trusted as well (self-hosted reverse proxies with an own CA). -->
+<network-security-config>
+ <base-config cleartextTrafficPermitted="true">
+ <trust-anchors>
+ <certificates src="system" />
+ <certificates src="user" />
+ </trust-anchors>
+ </base-config>
+</network-security-config>
diff --git a/android/app/src/main/res/xml/shortcuts.xml b/android/app/src/main/res/xml/shortcuts.xml
new file mode 100644
index 0000000..1ea6c42
--- /dev/null
+++ b/android/app/src/main/res/xml/shortcuts.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
+ <shortcut
+ android:shortcutId="settings"
+ android:enabled="true"
+ android:icon="@drawable/ic_shortcut_settings"
+ android:shortcutShortLabel="@string/settings_title"
+ android:shortcutLongLabel="@string/settings_title">
+ <intent
+ android:action="android.intent.action.VIEW"
+ android:targetPackage="io.github.dermilderjoghurt.mirrorsync"
+ android:targetClass="io.github.dermilderjoghurt.mirrorsync.SettingsActivity" />
+ </shortcut>
+</shortcuts>
diff --git a/android/build.gradle b/android/build.gradle
new file mode 100644
index 0000000..48d2fa1
--- /dev/null
+++ b/android/build.gradle
@@ -0,0 +1,3 @@
+plugins {
+ id "com.android.application" version "8.7.3" apply false
+}
diff --git a/android/gradle.properties b/android/gradle.properties
new file mode 100644
index 0000000..18825f9
--- /dev/null
+++ b/android/gradle.properties
@@ -0,0 +1,3 @@
+org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
+android.useAndroidX=true
+android.nonTransitiveRClass=true
diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..1b33c55
Binary files /dev/null and b/android/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..d4081da
--- /dev/null
+++ b/android/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,7 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/android/gradlew b/android/gradlew
new file mode 100755
index 0000000..23d15a9
--- /dev/null
+++ b/android/gradlew
@@ -0,0 +1,251 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH="\\\"\\\""
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/android/gradlew.bat b/android/gradlew.bat
new file mode 100644
index 0000000..5eed7ee
--- /dev/null
+++ b/android/gradlew.bat
@@ -0,0 +1,94 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/android/settings.gradle b/android/settings.gradle
new file mode 100644
index 0000000..a91ae50
--- /dev/null
+++ b/android/settings.gradle
@@ -0,0 +1,16 @@
+pluginManagement {
+ repositories {
+ google()
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+rootProject.name = "MirrorSync"
+include ":app"