Merge pull request #2228 from open-keychain/fix-notify

Do not re-enable contacts sync if first time wizard is not finished
This commit is contained in:
Dominik Schürmann 2017-11-28 16:20:39 +01:00 committed by GitHub
commit 537de5fdcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 62 deletions

View File

@ -119,7 +119,10 @@ public final class Constants {
public static final String LANGUAGE = "language";
public static final String KEY_SERVERS = "keyServers";
public static final String PREF_VERSION = "keyServersDefaultVersion";
public static final String FIRST_TIME = "firstTime";
// false if first time wizard has been finished
public static final String FIRST_TIME_WIZARD = "firstTime";
// false if app has been started at least once (also from background etc)
public static final String FIRST_TIME_APP = "firstTimeApp";
public static final String CACHED_CONSOLIDATE = "cachedConsolidate";
public static final String SEARCH_KEYSERVER = "search_keyserver_pref";
public static final String SEARCH_KEYBASE = "search_keybase_pref";

View File

@ -35,7 +35,6 @@ import android.widget.Toast;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.sufficientlysecure.keychain.network.TlsCertificatePinning;
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
import org.sufficientlysecure.keychain.service.KeyserverSyncAdapterService;
@ -99,19 +98,23 @@ public class KeychainApplication extends Application {
// Add OpenKeychain account to Android to link contacts with keys and keyserver sync
createAccountIfNecessary(this);
if (Preferences.getKeyserverSyncEnabled(this)) {
// will update a keyserver sync if the interval has changed
KeyserverSyncAdapterService.enableKeyserverSync(this);
}
Preferences preferences = Preferences.getPreferences(this);
if (preferences.isAppExecutedFirstTime()) {
preferences.setAppExecutedFirstTime(false);
// if first time, enable keyserver and contact sync
if (Preferences.getPreferences(this).isFirstTime()) {
KeyserverSyncAdapterService.enableKeyserverSync(this);
ContactSyncAdapterService.enableContactsSync(this);
preferences.setPrefVersionToCurrentVersion();
}
// Update keyserver list as needed
Preferences.getPreferences(this).upgradePreferences(this);
if (Preferences.getKeyserverSyncEnabled(this)) {
// will update a keyserver sync if the interval has changed
KeyserverSyncAdapterService.updateInterval(this);
}
// Upgrade preferences as needed
preferences.upgradePreferences(this);
TlsCertificatePinning.addPinnedCertificate("hkps.pool.sks-keyservers.net", getAssets(), "hkps.pool.sks-keyservers.net.CA.cer");
TlsCertificatePinning.addPinnedCertificate("pgp.mit.edu", getAssets(), "pgp.mit.edu.cer");

View File

@ -62,7 +62,7 @@ public class ContactSyncAdapterService extends Service {
new ContactHelper(ContactSyncAdapterService.this).writeKeysToContacts();
importKeys();
// importKeys();
}
@Override
@ -96,47 +96,6 @@ public class ContactSyncAdapterService extends Service {
}
}
private static void importKeys() {
// TODO: Import is currently disabled, until we implement proper origin management
// importDone.set(false);
// KeychainApplication.setupAccountAsNeeded(ContactSyncAdapterService.this);
// EmailKeyHelper.importContacts(getContext(), new Messenger(new Handler(Looper.getMainLooper(),
// new Handler.Callback() {
// @Override
// public boolean handleMessage(Message msg) {
// Bundle data = msg.getInputData();
// switch (msg.arg1) {
// case KeychainIntentServiceHandler.MESSAGE_OKAY:
// Log.d(Constants.TAG, "Syncing... Done.");
// synchronized (importDone) {
// importDone.set(true);
// importDone.notifyAll();
// }
// return true;
// case KeychainIntentServiceHandler.MESSAGE_UPDATE_PROGRESS:
// if (data.containsKey(KeychainIntentServiceHandler.DATA_PROGRESS) &&
// data.containsKey(KeychainIntentServiceHandler.DATA_PROGRESS_MAX)) {
// Log.d(Constants.TAG, "Syncing... Progress: " +
// data.getInt(KeychainIntentServiceHandler.DATA_PROGRESS) + "/" +
// data.getInt(KeychainIntentServiceHandler.DATA_PROGRESS_MAX));
// return false;
// }
// default:
// Log.d(Constants.TAG, "Syncing... " + msg.toString());
// return false;
// }
// }
// })));
// synchronized (importDone) {
// try {
// if (!importDone.get()) importDone.wait();
// } catch (InterruptedException e) {
// Log.w(Constants.TAG, e);
// return;
// }
// }
}
@Override
public IBinder onBind(Intent intent) {
return new ContactSyncAdapter().getSyncAdapterBinder();
@ -187,4 +146,46 @@ public class ContactSyncAdapterService extends Service {
new ContactHelper(context).deleteAllContacts();
}
}
// TODO: Import is currently disabled, until we implement proper origin management
// private static void importKeys() {
// importDone.set(false);
// KeychainApplication.setupAccountAsNeeded(ContactSyncAdapterService.this);
// EmailKeyHelper.importContacts(getContext(), new Messenger(new Handler(Looper.getMainLooper(),
// new Handler.Callback() {
// @Override
// public boolean handleMessage(Message msg) {
// Bundle data = msg.getInputData();
// switch (msg.arg1) {
// case KeychainIntentServiceHandler.MESSAGE_OKAY:
// Log.d(Constants.TAG, "Syncing... Done.");
// synchronized (importDone) {
// importDone.set(true);
// importDone.notifyAll();
// }
// return true;
// case KeychainIntentServiceHandler.MESSAGE_UPDATE_PROGRESS:
// if (data.containsKey(KeychainIntentServiceHandler.DATA_PROGRESS) &&
// data.containsKey(KeychainIntentServiceHandler.DATA_PROGRESS_MAX)) {
// Log.d(Constants.TAG, "Syncing... Progress: " +
// data.getInt(KeychainIntentServiceHandler.DATA_PROGRESS) + "/" +
// data.getInt(KeychainIntentServiceHandler.DATA_PROGRESS_MAX));
// return false;
// }
// default:
// Log.d(Constants.TAG, "Syncing... " + msg.toString());
// return false;
// }
// }
// })));
// synchronized (importDone) {
// try {
// if (!importDone.get()) importDone.wait();
// } catch (InterruptedException e) {
// Log.w(Constants.TAG, e);
// return;
// }
// }
// }
}

View File

@ -528,10 +528,6 @@ public class KeyserverSyncAdapterService extends Service {
return builder.build();
}
/**
* creates a new sync if one does not exist, or updates an existing sync if the sync interval
* has changed.
*/
public static void enableKeyserverSync(Context context) {
Account account = KeychainApplication.createAccountIfNecessary(context);
@ -543,6 +539,21 @@ public class KeyserverSyncAdapterService extends Service {
ContentResolver.setIsSyncable(account, Constants.PROVIDER_AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, Constants.PROVIDER_AUTHORITY, true);
updateInterval(context);
}
/**
* creates a new sync if one does not exist, or updates an existing sync if the sync interval
* has changed.
*/
public static void updateInterval(Context context) {
Account account = KeychainApplication.createAccountIfNecessary(context);
if (account == null) {
// account failed to be created for some reason, nothing we can do here
return;
}
boolean intervalChanged = false;
boolean syncExists = Preferences.getKeyserverSyncEnabled(context);

View File

@ -118,16 +118,22 @@ public class Preferences {
}
public boolean isFirstTime() {
return mSharedPreferences.getBoolean(Constants.Pref.FIRST_TIME, true);
}
public boolean useNumKeypadForSecurityTokenPin() {
return mSharedPreferences.getBoolean(Pref.USE_NUMKEYPAD_FOR_SECURITY_TOKEN_PIN, true);
return mSharedPreferences.getBoolean(Constants.Pref.FIRST_TIME_WIZARD, true);
}
public void setFirstTime(boolean value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(Constants.Pref.FIRST_TIME, value);
editor.putBoolean(Constants.Pref.FIRST_TIME_WIZARD, value);
editor.commit();
}
public boolean isAppExecutedFirstTime() {
return mSharedPreferences.getBoolean(Pref.FIRST_TIME_APP, true);
}
public void setAppExecutedFirstTime(boolean value) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(Constants.Pref.FIRST_TIME_APP, value);
editor.commit();
}
@ -215,6 +221,10 @@ public class Preferences {
editor.commit();
}
public boolean useNumKeypadForSecurityTokenPin() {
return mSharedPreferences.getBoolean(Pref.USE_NUMKEYPAD_FOR_SECURITY_TOKEN_PIN, true);
}
public void setUseNumKeypadForSecurityTokenPin(boolean useNumKeypad) {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putBoolean(Pref.USE_NUMKEYPAD_FOR_SECURITY_TOKEN_PIN, useNumKeypad);
@ -410,6 +420,12 @@ public class Preferences {
return mSharedPreferences.getBoolean(Pref.EXPERIMENTAL_SMARTPGP_VERIFY_AUTHORITY, false);
}
public void setPrefVersionToCurrentVersion() {
SharedPreferences.Editor editor = mSharedPreferences.edit();
editor.putInt(Pref.PREF_VERSION, Constants.Defaults.PREF_CURRENT_VERSION);
editor.commit();
}
public void upgradePreferences(Context context) {
Log.d(Constants.TAG, "Upgrading preferences…");
int oldVersion = mSharedPreferences.getInt(Constants.Pref.PREF_VERSION, 0);