diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java index bb691a9d2..964a15d58 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/KeychainApplication.java @@ -103,8 +103,6 @@ public class KeychainApplication extends Application { } } - - public static void setupAccountAsNeeded(Context context) { AccountManager manager = AccountManager.get(context); Account[] accounts = manager.getAccountsByType(Constants.PACKAGE_NAME); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java index 560eb9ef8..041c4d904 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainDatabase.java @@ -349,7 +349,7 @@ public class KeychainDatabase extends SQLiteOpenHelper { copy(in, out); } - // DANGEROUS + // DANGEROUS, use in test code ONLY! public void clearDatabase() { getWritableDatabase().execSQL("delete from " + Tables.KEY_RINGS_PUBLIC); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java index 2c552a060..c5bf12143 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/KeychainProvider.java @@ -685,6 +685,11 @@ public class KeychainProvider extends ContentProvider { final int match = mUriMatcher.match(uri); switch (match) { + // dangerous + case KEY_RINGS_UNIFIED: { + count = db.delete(Tables.KEY_RINGS_PUBLIC, null, null); + break; + } case KEY_RING_PUBLIC: { @SuppressWarnings("ConstantConditions") // ensured by uriMatcher above String selection = KeyRings.MASTER_KEY_ID + " = " + uri.getPathSegments().get(1); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java index 2867967ff..125f33ded 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java @@ -963,7 +963,6 @@ public class ProviderHelper { private ConsolidateResult consolidateDatabaseStep2(Progressable progress, boolean recovery) { - Preferences prefs = Preferences.getPreferences(mContext); // Set flag that we have a cached consolidation here @@ -986,7 +985,12 @@ public class ProviderHelper { // 2. wipe database (IT'S DANGEROUS) log(LogLevel.DEBUG, LogType.MSG_CON_DB_CLEAR); - new KeychainDatabase(mContext).clearDatabase(); + mContentResolver.delete(KeyRings.buildUnifiedKeyRingsUri(), null, null); + + // debug: break if this isn't recovery + if (!recovery) { + return new ConsolidateResult(ConsolidateResult.RESULT_ERROR, mLog); + } FileImportCache cacheSecret = new FileImportCache(mContext, "consolidate_secret.pcl"); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 99eab7f1d..d568df91a 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -167,6 +167,10 @@ public class KeychainIntentService extends IntentService public static final String CERTIFY_KEY_PUB_KEY_ID = "sign_key_pub_key_id"; public static final String CERTIFY_KEY_UIDS = "sign_key_uids"; + // consolidate + public static final String CONSOLIDATE_RECOVERY = "consolidate_recovery"; + + /* * possible data keys as result send over messenger */ @@ -181,8 +185,6 @@ public class KeychainIntentService extends IntentService // export public static final String RESULT_EXPORT = "exported"; - public static final String RESULT_CONSOLIDATE = "consolidate_result"; - Messenger mMessenger; private boolean mIsCanceled; @@ -665,7 +667,12 @@ public class KeychainIntentService extends IntentService } } else if (ACTION_CONSOLIDATE.equals(action)) { - ConsolidateResult result = new ProviderHelper(this).consolidateDatabaseStep1(this); + ConsolidateResult result; + if (data.containsKey(CONSOLIDATE_RECOVERY) && data.getBoolean(CONSOLIDATE_RECOVERY)) { + result = new ProviderHelper(this).consolidateDatabaseStep2(this); + } else { + result = new ProviderHelper(this).consolidateDatabaseStep1(this); + } sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ConsolidateDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ConsolidateDialogActivity.java index e4a80ff48..b21b1375e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ConsolidateDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ConsolidateDialogActivity.java @@ -20,7 +20,10 @@ package org.sufficientlysecure.keychain.ui; import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; +import android.content.Intent; import android.os.Bundle; +import android.os.Message; +import android.os.Messenger; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; import android.util.Log; @@ -29,6 +32,9 @@ import android.view.KeyEvent; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.service.KeychainIntentService; +import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; +import org.sufficientlysecure.keychain.service.OperationResults.ConsolidateResult; /** * We can not directly create a dialog on the application context. @@ -36,66 +42,65 @@ import org.sufficientlysecure.keychain.R; */ public class ConsolidateDialogActivity extends FragmentActivity { - MyDialogFragment mDialogFragment; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // this activity itself has no content view (see manifest) - mDialogFragment = new MyDialogFragment(); - // give all extras through to the fragment - mDialogFragment.setArguments(getIntent().getExtras()); + consolidateRecovery(); - mDialogFragment.show(getSupportFragmentManager(), "dialog"); } - public static class MyDialogFragment extends DialogFragment { + private void consolidateRecovery() { + // Message is received after importing is done in KeychainIntentService + KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler( + this, + getString(R.string.progress_importing), + ProgressDialog.STYLE_HORIZONTAL) { + public void handleMessage(Message message) { + // handle messages by standard KeychainIntentServiceHandler first + super.handleMessage(message); - /** - * Creates dialog - */ - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay - ContextThemeWrapper context = new ContextThemeWrapper(getActivity(), - R.style.Theme_AppCompat_Light); - ProgressDialog dialog = new ProgressDialog(context); - dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - dialog.setCancelable(false); - dialog.setCanceledOnTouchOutside(false); + if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) { + /* don't care about the results (for now?) - // Disable the back button - DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() { - @Override - public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - return true; + // get returned data bundle + Bundle returnData = message.getData(); + if (returnData == null) { + return; } - return false; + final ConsolidateResult result = + returnData.getParcelable(KeychainIntentService.RESULT_CONSOLIDATE); + if (result == null) { + return; + } + result.createNotify(ConsolidateDialogActivity.this).show(); + */ + + ConsolidateDialogActivity.this.finish(); } + } + }; - }; - dialog.setOnKeyListener(keyListener); + // Send all information needed to service to import key in other thread + Intent intent = new Intent(this, KeychainIntentService.class); + intent.setAction(KeychainIntentService.ACTION_CONSOLIDATE); - return dialog; - } + // fill values for this action + Bundle data = new Bundle(); + data.putBoolean(KeychainIntentService.CONSOLIDATE_RECOVERY, true); + intent.putExtra(KeychainIntentService.EXTRA_DATA, data); - @Override - public void onCancel(DialogInterface dialog) { - super.onCancel(dialog); + // Create a new Messenger for the communication back + Messenger messenger = new Messenger(saveHandler); + intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger); - dismiss(); - } + // show progress dialog + saveHandler.showProgressDialog(this); - @Override - public void onDismiss(DialogInterface dialog) { - super.onDismiss(dialog); - Log.d(Constants.TAG, "onDismiss"); - - getActivity().finish(); - } + // start service with intent + startService(intent); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java index 9d9462648..0bc98d545 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListActivity.java @@ -33,6 +33,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainDatabase; import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; +import org.sufficientlysecure.keychain.service.OperationResultParcel; import org.sufficientlysecure.keychain.service.OperationResults.ConsolidateResult; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Notify; @@ -164,7 +165,7 @@ public class KeyListActivity extends DrawerActivity { return; } final ConsolidateResult result = - returnData.getParcelable(KeychainIntentService.RESULT_CONSOLIDATE); + returnData.getParcelable(OperationResultParcel.EXTRA_RESULT); if (result == null) { return; } diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 1bd412d4d..64c743ead 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -703,7 +703,7 @@ No secret keys to reimport, skipping… Exception deleting public cache file - Exception deleting public cache file + Exception deleting secret cache file Click to clear cached passphrases