Catch security exception, known problem...

This commit is contained in:
Dominik Schürmann 2014-09-02 13:51:09 +02:00
parent b547258df6
commit 0c437acd43
2 changed files with 24 additions and 13 deletions

View File

@ -28,6 +28,7 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Environment;
import android.provider.ContactsContract;
import android.widget.Toast;
import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.sufficientlysecure.keychain.helper.Preferences;
@ -96,34 +97,43 @@ public class KeychainApplication extends Application {
TemporaryStorageProvider.cleanUp(this);
checkConsolidateRecovery();
}
/**
* Restart consolidate process if it has been interruped before
*/
public void checkConsolidateRecovery() {
// restart consolidate process if it has been interruped before
if (Preferences.getPreferences(this).getCachedConsolidate()) {
// do something which calls ProviderHelper.consolidateDatabaseStep2 with a progressable
Intent consolidateIntent = new Intent(this, ConsolidateDialogActivity.class);
consolidateIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(consolidateIntent);
}
}
/**
* Add OpenKeychain account to Android to link contacts with keys
*
* @param context
*/
public static void setupAccountAsNeeded(Context context) {
// only enabled for Jelly Bean because we need some newer methods in our sync adapter
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
AccountManager manager = AccountManager.get(context);
Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE);
if (accounts == null || accounts.length == 0) {
Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE);
if (manager.addAccountExplicitly(account, null, null)) {
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
} else {
Log.e(Constants.TAG, "Adding account failed!");
try {
AccountManager manager = AccountManager.get(context);
Account[] accounts = manager.getAccountsByType(Constants.ACCOUNT_TYPE);
if (accounts == null || accounts.length == 0) {
Account account = new Account(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE);
if (manager.addAccountExplicitly(account, null, null)) {
ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
ContentResolver.setSyncAutomatically(account, ContactsContract.AUTHORITY, true);
} else {
Log.e(Constants.TAG, "Adding account failed!");
}
}
} catch (SecurityException e) {
Log.e(Constants.TAG, "SecurityException when adding the account", e);
Toast.makeText(context, R.string.reinstall_openkeychain, Toast.LENGTH_LONG).show();
}
}
}

View File

@ -193,6 +193,7 @@
<string name="secret_key_deletion_confirmation">"Do you really want to delete the SECRET key \'%s\'?\nYou can\'t undo this!"</string>
<string name="public_key_deletetion_confirmation">"Do you really want to delete the public key \'%s\'?\nYou can\'t undo this!"</string>
<string name="also_export_secret_keys">Also export secret keys</string>
<string name="reinstall_openkeychain">You encountered a known bug with Android. Please reinstall OpenKeychain if you want to link your contacts with keys.</string>
<string name="key_exported">Successfully exported 1 key.</string>
<string name="keys_exported">Successfully exported %d keys.</string>