Skip to content

Commit

Permalink
Merge pull request #1 from MaeIsBad/master
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
Bartixxx32 committed Jun 15, 2022
2 parents 55d2f8b + 00ad4bd commit f33b453
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 2 deletions.
18 changes: 17 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
package="info.varden.hauk">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>


<application
android:allowBackup="true"
Expand Down Expand Up @@ -45,14 +48,27 @@
</activity>

<receiver
android:name=".global.Receiver"
android:name=".global.ExportedReceiver"
android:exported="true"
tools:ignore="ExportedReceiver">
<intent-filter>
<action android:name="info.varden.hauk.START_ALONE_THEN_SHARE_VIA" />
<action android:name="info.varden.hauk.START_ALONE_THEN_MAKE_TOAST" />
</intent-filter>
</receiver>

<receiver
android:name=".global.RebootReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">

<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

</receiver>

<receiver
android:name=".notify.CopyLinkReceiver"
android:exported="false">
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/java/info/varden/hauk/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public enum Constants {
public static final Preference<String> PREF_NICKNAME = new Preference.String("nickname", "");
public static final Preference<Integer> PREF_DURATION_UNIT = new Preference.Integer("durUnit", Constants.DURATION_UNIT_MINUTES);
public static final Preference<Boolean> PREF_ALLOW_ADOPTION = new Preference.Boolean("allowAdoption", true);
public static final Preference<Boolean> PREF_RESTART_ON_BOOT = new Preference.Boolean("restartOnBoot", true);
public static final Preference<NightModeStyle> PREF_NIGHT_MODE = new Preference.Enum<>("nightMode", NightModeStyle.FOLLOW_SYSTEM);
public static final Preference<Boolean> PREF_CONFIRM_STOP = new Preference.Boolean("confirmStop", true);
public static final Preference<Boolean> PREF_HIDE_LOGO = new Preference.Boolean("hideLogo", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@
<string name="tls_validation_no_anchor_onion">Disable trust anchor validation for .onion hosts (not recommended)</string>
<string name="tls_validation_none_for_onion">Disable trust anchor and hostname validation for .onion hosts (not recommended)</string>

<string name="pref_restartOnBoot_title">Resume shares on device restart</string>
<string name="pref_restartOnBoot_summaryOn">Resume shares on boot</string>
<string name="pref_restartOnBoot_summaryOff">Do not resume shares on boot</string>

<!-- Appearance settings -->
<string name="prefs_header_appearance">Appearance</string>
<string name="prefs_nightMode_title">Night mode</string>
Expand Down
5 changes: 5 additions & 0 deletions android/app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@
app:entries="@array/tls_validation_types"
app:entryValues="@array/tls_validation_type_values" />

<SwitchPreference
app:key="restartOnBoot"
app:title="@string/pref_restartOnBoot_title"
app:summaryOff="@string/pref_restartOnBoot_summaryOff"
app:summaryOn="@string/pref_restartOnBoot_summaryOn" />
</PreferenceCategory>

<PreferenceCategory app:title="@string/prefs_header_appearance">
Expand Down

0 comments on commit f33b453

Please sign in to comment.