Final commit
All changes included Improvements -Reformatted code wherever required -Only active wifi connections trigger events -Improve sync reliability -Removed extra permission Minor Changes -Refactored 2 variables for easier readbility -Wifi-Only-Sync is now enabled by default
This commit is contained in:
parent
2b43ba438b
commit
cab3fa7874
|
@ -76,6 +76,7 @@
|
|||
|
||||
<!-- other group (for free) -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.NFC" />
|
||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
||||
|
@ -89,6 +90,15 @@
|
|||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/Theme.Keychain.Light">
|
||||
<!-- broadcast receiver for Wi-Fi Connection -->
|
||||
<receiver
|
||||
android:name=".receiver.NetworkReceiver"
|
||||
android:enabled="false"
|
||||
android:exported="true" >
|
||||
<intent-filter>
|
||||
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<!-- singleTop for NFC dispatch, see SecurityTokenOperationActivity -->
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
|
|
|
@ -118,6 +118,7 @@ public final class Constants {
|
|||
// keyserver sync settings
|
||||
public static final String SYNC_CONTACTS = "syncContacts";
|
||||
public static final String SYNC_KEYSERVER = "syncKeyserver";
|
||||
public static final String ENABLE_WIFI_SYNC_ONLY = "enableWifiSyncOnly";
|
||||
// other settings
|
||||
public static final String EXPERIMENTAL_ENABLE_WORD_CONFIRM = "experimentalEnableWordConfirm";
|
||||
public static final String EXPERIMENTAL_ENABLE_LINKED_IDENTITIES = "experimentalEnableLinkedIdentities";
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package org.sufficientlysecure.keychain.receiver;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
public class NetworkReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
ConnectivityManager conn = (ConnectivityManager)
|
||||
context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = conn.getActiveNetworkInfo();
|
||||
boolean isTypeWifi = (networkInfo.getType() == ConnectivityManager.TYPE_WIFI);
|
||||
boolean isConnected = networkInfo.isConnected();
|
||||
|
||||
if (isTypeWifi && isConnected) {
|
||||
|
||||
// broadcaster receiver disabled
|
||||
setWifiReceiverComponent(false, context);
|
||||
Intent serviceIntent = new Intent(context, KeyserverSyncAdapterService.class);
|
||||
serviceIntent.setAction(KeyserverSyncAdapterService.ACTION_SYNC_NOW);
|
||||
context.startService(serviceIntent);
|
||||
}
|
||||
}
|
||||
|
||||
public void setWifiReceiverComponent(Boolean isEnabled, Context context) {
|
||||
|
||||
PackageManager pm = context.getPackageManager();
|
||||
ComponentName compName = new ComponentName(context,
|
||||
NetworkReceiver.class);
|
||||
|
||||
if (isEnabled) {
|
||||
pm.setComponentEnabledSetting(compName,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
|
||||
Log.d(Constants.TAG, "Wifi Receiver is enabled!");
|
||||
} else {
|
||||
pm.setComponentEnabledSetting(compName,
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||
Log.d(Constants.TAG, "Wifi Receiver is disabled!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import android.Manifest;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
|
@ -59,6 +57,8 @@ import org.sufficientlysecure.keychain.util.Log;
|
|||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
|
||||
public static final int REQUEST_CODE_KEYSERVER_PREF = 0x00007005;
|
||||
|
@ -405,7 +405,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||
}
|
||||
|
||||
/**
|
||||
* This fragment shows the keyserver/contacts sync preferences
|
||||
* This fragment shows the keyserver/wifi-only-sync/contacts sync preferences
|
||||
*/
|
||||
public static class SyncPrefsFragment extends PresetPreferenceFragment {
|
||||
|
||||
|
|
|
@ -19,19 +19,6 @@
|
|||
package org.sufficientlysecure.keychain.util;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -45,6 +32,19 @@ import org.sufficientlysecure.keychain.Constants.Pref;
|
|||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Singleton Implementation of a Preference Helper
|
||||
*/
|
||||
|
@ -424,6 +424,12 @@ public class Preferences {
|
|||
};
|
||||
}
|
||||
|
||||
// sync preferences
|
||||
|
||||
public boolean getWifiOnlySync() {
|
||||
return mSharedPreferences.getBoolean(Pref.ENABLE_WIFI_SYNC_ONLY, true);
|
||||
}
|
||||
|
||||
// experimental prefs
|
||||
|
||||
public boolean getExperimentalEnableWordConfirm() {
|
||||
|
|
|
@ -201,6 +201,7 @@
|
|||
<string name="label_sync_settings_keyserver_title">"Automatic key updates"</string>
|
||||
<string name="label_sync_settings_keyserver_summary_on">"Every three days, keys are updated from the preferred keyserver"</string>
|
||||
<string name="label_sync_settings_keyserver_summary_off">"Keys are not automatically updated"</string>
|
||||
<string name="label_sync_settings_wifi_title">"Sync only on Wi-Fi"</string>
|
||||
<string name="label_sync_settings_contacts_title">"Link keys to contacts"</string>
|
||||
<string name="label_sync_settings_contacts_summary_on">"Link keys to contacts based on names and email addresses. This happens completely offline on your device."</string>
|
||||
<string name="label_sync_settings_contacts_summary_off">"New keys will not be linked to contacts"</string>
|
||||
|
|
|
@ -3,6 +3,12 @@
|
|||
android:key="syncKeyserver"
|
||||
android:persistent="false"
|
||||
android:title="@string/label_sync_settings_keyserver_title"/>
|
||||
<SwitchPreference
|
||||
android:key="enableWifiSyncOnly"
|
||||
android:defaultValue="true"
|
||||
android:persistent="true"
|
||||
android:dependency="syncKeyserver"
|
||||
android:title="@string/label_sync_settings_wifi_title"/>
|
||||
<SwitchPreference
|
||||
android:key="syncContacts"
|
||||
android:persistent="false"
|
||||
|
|
Loading…
Reference in a new issue