Merge pull request #1785 from advaita13/wifi-only-fix
Sync only when unmetered internet is available #1670
This commit is contained in:
@@ -144,12 +144,13 @@ public class ContactSyncAdapterService extends Service {
|
||||
|
||||
public static void requestContactsSync() {
|
||||
// if user has disabled automatic sync, do nothing
|
||||
if (!ContentResolver.getSyncAutomatically(
|
||||
new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE),
|
||||
ContactsContract.AUTHORITY)) {
|
||||
boolean isSyncEnabled = ContentResolver.getSyncAutomatically(new Account
|
||||
(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE), ContactsContract.AUTHORITY);
|
||||
|
||||
if (!isSyncEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Bundle extras = new Bundle();
|
||||
// no need to wait, do it immediately
|
||||
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
|
||||
|
||||
@@ -16,6 +16,8 @@ import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -35,6 +37,7 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.receiver.NetworkReceiver;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
@@ -68,7 +71,7 @@ public class KeyserverSyncAdapterService extends Service {
|
||||
|
||||
private static final String ACTION_IGNORE_TOR = "ignore_tor";
|
||||
private static final String ACTION_UPDATE_ALL = "update_all";
|
||||
private static final String ACTION_SYNC_NOW = "sync_now";
|
||||
public static final String ACTION_SYNC_NOW = "sync_now";
|
||||
private static final String ACTION_DISMISS_NOTIFICATION = "cancel_sync";
|
||||
private static final String ACTION_START_ORBOT = "start_orbot";
|
||||
private static final String ACTION_CANCEL = "cancel";
|
||||
@@ -176,8 +179,25 @@ public class KeyserverSyncAdapterService extends Service {
|
||||
@Override
|
||||
public void onPerformSync(Account account, Bundle extras, String authority,
|
||||
ContentProviderClient provider, SyncResult syncResult) {
|
||||
Log.d(Constants.TAG, "Performing a keyserver sync!");
|
||||
|
||||
Preferences prefs = Preferences.getPreferences(getContext());
|
||||
|
||||
// for a wifi-ONLY sync
|
||||
if (prefs.getWifiOnlySync()) {
|
||||
|
||||
ConnectivityManager connMgr = (ConnectivityManager)
|
||||
getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
boolean isNotOnWifi = !(networkInfo.getType() == ConnectivityManager.TYPE_WIFI);
|
||||
boolean isNotConnected = !(networkInfo.isConnected());
|
||||
|
||||
// if Wi-Fi connection doesn't exist then receiver is enabled
|
||||
if (isNotOnWifi && isNotConnected) {
|
||||
new NetworkReceiver().setWifiReceiverComponent(true, getContext());
|
||||
return;
|
||||
}
|
||||
}
|
||||
Log.d(Constants.TAG, "Performing a keyserver sync!");
|
||||
PowerManager pm = (PowerManager) KeyserverSyncAdapterService.this
|
||||
.getSystemService(Context.POWER_SERVICE);
|
||||
@SuppressWarnings("deprecation") // our min is API 15, deprecated only in 20
|
||||
|
||||
Reference in New Issue
Block a user