From e6263e7a9ff2bceecc7c72c31e035b1a31909c20 Mon Sep 17 00:00:00 2001
From: Mae <88627318+MaeIsBad@users.noreply.github.com>
Date: Sun, 8 Aug 2021 19:24:55 +0200
Subject: [PATCH 1/2] Automatically resume shares on device start This commit
adds an option to automatically resume active shares on device reboot.
---
android/app/src/main/AndroidManifest.xml | 17 ++++++-
.../main/java/info/varden/hauk/Constants.java | 1 +
.../{Receiver.java => ExportedReceiver.java} | 2 +-
.../varden/hauk/global/RebootReceiver.java | 48 +++++++++++++++++++
.../varden/hauk/manager/SessionManager.java | 10 ++++
android/app/src/main/res/values/strings.xml | 4 ++
.../app/src/main/res/xml/root_preferences.xml | 5 ++
7 files changed, 85 insertions(+), 2 deletions(-)
rename android/app/src/main/java/info/varden/hauk/global/{Receiver.java => ExportedReceiver.java} (99%)
create mode 100644 android/app/src/main/java/info/varden/hauk/global/RebootReceiver.java
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 2ff1504..20983e0 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -6,6 +6,8 @@
+
+
@@ -53,6 +55,19 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/app/src/main/java/info/varden/hauk/Constants.java b/android/app/src/main/java/info/varden/hauk/Constants.java
index a6909af..e75524b 100644
--- a/android/app/src/main/java/info/varden/hauk/Constants.java
+++ b/android/app/src/main/java/info/varden/hauk/Constants.java
@@ -45,6 +45,7 @@ public enum Constants {
public static final Preference PREF_NICKNAME = new Preference.String("nickname", "");
public static final Preference PREF_DURATION_UNIT = new Preference.Integer("durUnit", Constants.DURATION_UNIT_MINUTES);
public static final Preference PREF_ALLOW_ADOPTION = new Preference.Boolean("allowAdoption", true);
+ public static final Preference PREF_RESTART_ON_BOOT = new Preference.Boolean("restartOnBoot", true);
public static final Preference PREF_NIGHT_MODE = new Preference.Enum<>("nightMode", NightModeStyle.FOLLOW_SYSTEM);
public static final Preference PREF_CONFIRM_STOP = new Preference.Boolean("confirmStop", true);
public static final Preference PREF_HIDE_LOGO = new Preference.Boolean("hideLogo", false);
diff --git a/android/app/src/main/java/info/varden/hauk/global/Receiver.java b/android/app/src/main/java/info/varden/hauk/global/ExportedReceiver.java
similarity index 99%
rename from android/app/src/main/java/info/varden/hauk/global/Receiver.java
rename to android/app/src/main/java/info/varden/hauk/global/ExportedReceiver.java
index a6d1eb4..6bb4dd6 100644
--- a/android/app/src/main/java/info/varden/hauk/global/Receiver.java
+++ b/android/app/src/main/java/info/varden/hauk/global/ExportedReceiver.java
@@ -51,7 +51,7 @@
* @since 1.3
* @author Marius Lindvall
*/
-public final class Receiver extends BroadcastReceiver {
+public final class ExportedReceiver extends BroadcastReceiver {
@SuppressWarnings("HardCodedStringLiteral")
private static final String ACTION_START_SHARING_ALONE_WITH_MENU = "info.varden.hauk.START_ALONE_THEN_SHARE_VIA";
@SuppressWarnings("HardCodedStringLiteral")
diff --git a/android/app/src/main/java/info/varden/hauk/global/RebootReceiver.java b/android/app/src/main/java/info/varden/hauk/global/RebootReceiver.java
new file mode 100644
index 0000000..04a4142
--- /dev/null
+++ b/android/app/src/main/java/info/varden/hauk/global/RebootReceiver.java
@@ -0,0 +1,48 @@
+package info.varden.hauk.global;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.widget.Toast;
+
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.SocketAddress;
+
+import info.varden.hauk.Constants;
+import info.varden.hauk.R;
+import info.varden.hauk.global.ui.AuthorizationActivity;
+import info.varden.hauk.global.ui.DisplayShareDialogListener;
+import info.varden.hauk.global.ui.toast.GNSSStatusUpdateListenerImpl;
+import info.varden.hauk.global.ui.toast.SessionInitiationResponseHandlerImpl;
+import info.varden.hauk.global.ui.toast.ShareListenerImpl;
+import info.varden.hauk.http.ConnectionParameters;
+import info.varden.hauk.http.SessionInitiationPacket;
+import info.varden.hauk.http.security.CertificateValidationPolicy;
+import info.varden.hauk.manager.SessionManager;
+import info.varden.hauk.struct.AdoptabilityPreference;
+import info.varden.hauk.system.LocationPermissionsNotGrantedException;
+import info.varden.hauk.system.LocationServicesDisabledException;
+import info.varden.hauk.system.preferences.PreferenceManager;
+import info.varden.hauk.utils.DeprecationMigrator;
+import info.varden.hauk.utils.Log;
+import info.varden.hauk.utils.TimeUtils;
+// Reboot broadcast receiver for Hauk. If enabled resumes a share session if one exists on device restart
+public final class RebootReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ // Subsequent calls may result in data being read from preferences. We should ensure that
+ // all deprecated preferences have been migrated before we continue.
+ new DeprecationMigrator(context).migrate();
+
+ PreferenceManager prefs = new PreferenceManager(context);
+ if(prefs.get(Constants.PREF_RESTART_ON_BOOT))
+ resumeShare(context,intent);
+ }
+ private void resumeShare(Context context, Intent intent) {
+ Log.d("Trying to resume shares...");
+ new BroadcastSessionManager(context).resumeShares();
+ }
+}
diff --git a/android/app/src/main/java/info/varden/hauk/manager/SessionManager.java b/android/app/src/main/java/info/varden/hauk/manager/SessionManager.java
index 2cf388e..085907c 100644
--- a/android/app/src/main/java/info/varden/hauk/manager/SessionManager.java
+++ b/android/app/src/main/java/info/varden/hauk/manager/SessionManager.java
@@ -206,6 +206,15 @@ public final void resumeShares(ResumePrompt prompt) {
}
}
+ public final void resumeShares() {
+ if (pusher != null) {
+ Log.d("Pusher is non-null (%s), stopping and nulling it before calling service relauncher", pusher); //NON-NLS
+ this.ctx.stopService(pusher);
+ pusher = null;
+ }
+ this.resumable.tryResumeShare(new ServiceRelauncher(this, this.resumable));
+ }
+
/**
* A preparation step for initiating sessions. Checks location services status and instantiates
* a response handler for the session initiation packet.
@@ -448,6 +457,7 @@ private boolean hasLocationPermission() {
}
}
+
/**
* The GNSS status handler that the {@link SessionManager} itself uses to receive status updates
* from the GNSS listeners. Used to propagate events further upstream.
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index 8370c12..7fe2400 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -155,6 +155,10 @@
Disable trust anchor validation for .onion hosts (not recommended)
Disable trust anchor and hostname validation for .onion hosts (not recommended)
+ Resume shares on device restart
+ Resume shares on boot
+ Do not resume shares on boot
+
Appearance
Night mode
diff --git a/android/app/src/main/res/xml/root_preferences.xml b/android/app/src/main/res/xml/root_preferences.xml
index addb5e5..8ca2585 100644
--- a/android/app/src/main/res/xml/root_preferences.xml
+++ b/android/app/src/main/res/xml/root_preferences.xml
@@ -104,6 +104,11 @@
app:entries="@array/tls_validation_types"
app:entryValues="@array/tls_validation_type_values" />
+
From 00ad4bddb70d9a61755c16b0c6d7bc355117ad34 Mon Sep 17 00:00:00 2001
From: Mae <88627318+MaeIsBad@users.noreply.github.com>
Date: Mon, 23 Aug 2021 01:52:31 +0200
Subject: [PATCH 2/2] Fix sharing not resuming on boot under android 11
Due to access restrictions introduced under android
11(https://developer.android.com/guide/components/foreground-services#access-restrictions)
you need an additional permissions to start recieveing location from a
service that wasn't started by a foreground activity
---
android/app/src/main/AndroidManifest.xml | 1 +
1 file changed, 1 insertion(+)
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index 20983e0..b42607e 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -4,6 +4,7 @@
package="info.varden.hauk">
+