1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-23 12:51:16 +00:00

Fix network broadcasts on Android 7 (fixes #783)

This commit is contained in:
Felix Ableitner 2016-11-20 23:10:38 +09:00
parent 113d712d5f
commit 8fc957a56b

View file

@ -9,6 +9,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
@ -26,6 +27,7 @@ import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.activities.MainActivity; import com.nutomic.syncthingandroid.activities.MainActivity;
import com.nutomic.syncthingandroid.http.PollWebGuiAvailableTask; import com.nutomic.syncthingandroid.http.PollWebGuiAvailableTask;
import com.nutomic.syncthingandroid.model.Folder; import com.nutomic.syncthingandroid.model.Folder;
import com.nutomic.syncthingandroid.receiver.NetworkReceiver;
import com.nutomic.syncthingandroid.util.ConfigXml; import com.nutomic.syncthingandroid.util.ConfigXml;
import com.nutomic.syncthingandroid.util.FolderObserver; import com.nutomic.syncthingandroid.util.FolderObserver;
@ -104,6 +106,8 @@ public class SyncthingService extends Service implements
private final SyncthingServiceBinder mBinder = new SyncthingServiceBinder(this); private final SyncthingServiceBinder mBinder = new SyncthingServiceBinder(this);
private final NetworkReceiver mNetworkReceiver = new NetworkReceiver();
/** /**
* Callback for when the Syncthing web interface becomes first available after service start. * Callback for when the Syncthing web interface becomes first available after service start.
*/ */
@ -306,6 +310,13 @@ public class SyncthingService extends Service implements
registerReceiver(mPowerSaveModeChangedReceiver, registerReceiver(mPowerSaveModeChangedReceiver,
new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED)); new IntentFilter(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED));
} }
// Android 7 ignores network receiver that was set in manifest
// https://github.com/syncthing/syncthing-android/issues/783
// https://developer.android.com/about/versions/nougat/android-7.0-changes.html#bg-opt
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
registerReceiver(mNetworkReceiver,
new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
}
new StartupTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new StartupTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
PreferenceManager.getDefaultSharedPreferences(this) PreferenceManager.getDefaultSharedPreferences(this)
.registerOnSharedPreferenceChangeListener(this); .registerOnSharedPreferenceChangeListener(this);
@ -397,6 +408,8 @@ public class SyncthingService extends Service implements
sp.unregisterOnSharedPreferenceChangeListener(this); sp.unregisterOnSharedPreferenceChangeListener(this);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB)
unregisterReceiver(mPowerSaveModeChangedReceiver); unregisterReceiver(mPowerSaveModeChangedReceiver);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N)
unregisterReceiver(mNetworkReceiver);
} }
private void shutdown() { private void shutdown() {