mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-25 16:38:50 -05:00
Merge branch 'master' of github.com:open-keychain/open-keychain
Conflicts: OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
This commit is contained in:
commit
0e152d1db0
@ -103,8 +103,6 @@ public class KeychainApplication extends Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void setupAccountAsNeeded(Context context) {
|
public static void setupAccountAsNeeded(Context context) {
|
||||||
AccountManager manager = AccountManager.get(context);
|
AccountManager manager = AccountManager.get(context);
|
||||||
Account[] accounts = manager.getAccountsByType(Constants.PACKAGE_NAME);
|
Account[] accounts = manager.getAccountsByType(Constants.PACKAGE_NAME);
|
||||||
|
@ -349,7 +349,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
|
|||||||
copy(in, out);
|
copy(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DANGEROUS
|
// DANGEROUS, use in test code ONLY!
|
||||||
public void clearDatabase() {
|
public void clearDatabase() {
|
||||||
getWritableDatabase().execSQL("delete from " + Tables.KEY_RINGS_PUBLIC);
|
getWritableDatabase().execSQL("delete from " + Tables.KEY_RINGS_PUBLIC);
|
||||||
}
|
}
|
||||||
|
@ -685,6 +685,11 @@ public class KeychainProvider extends ContentProvider {
|
|||||||
final int match = mUriMatcher.match(uri);
|
final int match = mUriMatcher.match(uri);
|
||||||
|
|
||||||
switch (match) {
|
switch (match) {
|
||||||
|
// dangerous
|
||||||
|
case KEY_RINGS_UNIFIED: {
|
||||||
|
count = db.delete(Tables.KEY_RINGS_PUBLIC, null, null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case KEY_RING_PUBLIC: {
|
case KEY_RING_PUBLIC: {
|
||||||
@SuppressWarnings("ConstantConditions") // ensured by uriMatcher above
|
@SuppressWarnings("ConstantConditions") // ensured by uriMatcher above
|
||||||
String selection = KeyRings.MASTER_KEY_ID + " = " + uri.getPathSegments().get(1);
|
String selection = KeyRings.MASTER_KEY_ID + " = " + uri.getPathSegments().get(1);
|
||||||
|
@ -963,7 +963,6 @@ public class ProviderHelper {
|
|||||||
|
|
||||||
private ConsolidateResult consolidateDatabaseStep2(Progressable progress, boolean recovery) {
|
private ConsolidateResult consolidateDatabaseStep2(Progressable progress, boolean recovery) {
|
||||||
|
|
||||||
|
|
||||||
Preferences prefs = Preferences.getPreferences(mContext);
|
Preferences prefs = Preferences.getPreferences(mContext);
|
||||||
|
|
||||||
// Set flag that we have a cached consolidation here
|
// Set flag that we have a cached consolidation here
|
||||||
@ -986,7 +985,12 @@ public class ProviderHelper {
|
|||||||
|
|
||||||
// 2. wipe database (IT'S DANGEROUS)
|
// 2. wipe database (IT'S DANGEROUS)
|
||||||
log(LogLevel.DEBUG, LogType.MSG_CON_DB_CLEAR);
|
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<ParcelableKeyRing> cacheSecret =
|
FileImportCache<ParcelableKeyRing> cacheSecret =
|
||||||
new FileImportCache<ParcelableKeyRing>(mContext, "consolidate_secret.pcl");
|
new FileImportCache<ParcelableKeyRing>(mContext, "consolidate_secret.pcl");
|
||||||
|
@ -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_PUB_KEY_ID = "sign_key_pub_key_id";
|
||||||
public static final String CERTIFY_KEY_UIDS = "sign_key_uids";
|
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
|
* possible data keys as result send over messenger
|
||||||
*/
|
*/
|
||||||
@ -181,8 +185,6 @@ public class KeychainIntentService extends IntentService
|
|||||||
// export
|
// export
|
||||||
public static final String RESULT_EXPORT = "exported";
|
public static final String RESULT_EXPORT = "exported";
|
||||||
|
|
||||||
public static final String RESULT_CONSOLIDATE = "consolidate_result";
|
|
||||||
|
|
||||||
Messenger mMessenger;
|
Messenger mMessenger;
|
||||||
|
|
||||||
private boolean mIsCanceled;
|
private boolean mIsCanceled;
|
||||||
@ -665,7 +667,12 @@ public class KeychainIntentService extends IntentService
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (ACTION_CONSOLIDATE.equals(action)) {
|
} 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);
|
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,10 @@ package org.sufficientlysecure.keychain.ui;
|
|||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -29,6 +32,9 @@ import android.view.KeyEvent;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
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.
|
* 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 {
|
public class ConsolidateDialogActivity extends FragmentActivity {
|
||||||
|
|
||||||
MyDialogFragment mDialogFragment;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// this activity itself has no content view (see manifest)
|
// this activity itself has no content view (see manifest)
|
||||||
|
|
||||||
mDialogFragment = new MyDialogFragment();
|
consolidateRecovery();
|
||||||
// give all extras through to the fragment
|
|
||||||
mDialogFragment.setArguments(getIntent().getExtras());
|
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
/**
|
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||||
* Creates dialog
|
/* don't care about the results (for now?)
|
||||||
*/
|
|
||||||
@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);
|
|
||||||
|
|
||||||
// Disable the back button
|
// get returned data bundle
|
||||||
DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() {
|
Bundle returnData = message.getData();
|
||||||
@Override
|
if (returnData == null) {
|
||||||
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
return;
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
final ConsolidateResult result =
|
||||||
|
returnData.getParcelable(KeychainIntentService.RESULT_CONSOLIDATE);
|
||||||
|
if (result == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
result.createNotify(ConsolidateDialogActivity.this).show();
|
||||||
|
*/
|
||||||
|
|
||||||
|
ConsolidateDialogActivity.this.finish();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
};
|
// Send all information needed to service to import key in other thread
|
||||||
dialog.setOnKeyListener(keyListener);
|
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
|
// Create a new Messenger for the communication back
|
||||||
public void onCancel(DialogInterface dialog) {
|
Messenger messenger = new Messenger(saveHandler);
|
||||||
super.onCancel(dialog);
|
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
dismiss();
|
// show progress dialog
|
||||||
}
|
saveHandler.showProgressDialog(this);
|
||||||
|
|
||||||
@Override
|
// start service with intent
|
||||||
public void onDismiss(DialogInterface dialog) {
|
startService(intent);
|
||||||
super.onDismiss(dialog);
|
|
||||||
Log.d(Constants.TAG, "onDismiss");
|
|
||||||
|
|
||||||
getActivity().finish();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
|
import org.sufficientlysecure.keychain.service.OperationResultParcel;
|
||||||
import org.sufficientlysecure.keychain.service.OperationResults.ConsolidateResult;
|
import org.sufficientlysecure.keychain.service.OperationResults.ConsolidateResult;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Notify;
|
import org.sufficientlysecure.keychain.util.Notify;
|
||||||
@ -164,7 +165,7 @@ public class KeyListActivity extends DrawerActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ConsolidateResult result =
|
final ConsolidateResult result =
|
||||||
returnData.getParcelable(KeychainIntentService.RESULT_CONSOLIDATE);
|
returnData.getParcelable(OperationResultParcel.EXTRA_RESULT);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -703,7 +703,7 @@
|
|||||||
</plurals>
|
</plurals>
|
||||||
<string name="msg_con_reimport_secret_skip">No secret keys to reimport, skipping…</string>
|
<string name="msg_con_reimport_secret_skip">No secret keys to reimport, skipping…</string>
|
||||||
<string name="msg_con_warn_delete_public">Exception deleting public cache file</string>
|
<string name="msg_con_warn_delete_public">Exception deleting public cache file</string>
|
||||||
<string name="msg_con_warn_delete_secret">Exception deleting public cache file</string>
|
<string name="msg_con_warn_delete_secret">Exception deleting secret cache file</string>
|
||||||
|
|
||||||
<!-- PassphraseCache -->
|
<!-- PassphraseCache -->
|
||||||
<string name="passp_cache_notif_click_to_clear">Click to clear cached passphrases</string>
|
<string name="passp_cache_notif_click_to_clear">Click to clear cached passphrases</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user