From f3bbd344823265f2b77cfc0af530a23211663e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 17 Feb 2014 19:06:29 +0100 Subject: [PATCH] Fix register activity --- .../demo/OpenPgpProviderActivity.java | 1 - .../service/remote/RemoteService.java | 154 +++++++++--------- .../service/remote/RemoteServiceActivity.java | 73 ++------- 3 files changed, 92 insertions(+), 136 deletions(-) diff --git a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java index 24d1c0456..d089b7285 100644 --- a/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java +++ b/OpenPGP-Keychain-API/example-app/src/main/java/org/sufficientlysecure/keychain/demo/OpenPgpProviderActivity.java @@ -192,7 +192,6 @@ public class OpenPgpProviderActivity extends Activity { } } - public void sign(Bundle params) { params.putBoolean(OpenPgpConstants.PARAMS_REQUEST_ASCII_ARMOR, true); diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java index bcfe37368..bfea70381 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteService.java @@ -168,30 +168,30 @@ public abstract class RemoteService extends Service { /** * Locks current thread and pauses execution of runnables and starts activity for user input */ - protected void pauseAndStartUserInteraction(String action, BaseCallback callback, Bundle extras) { - synchronized (userInputLock) { - mThreadPool.pause(); - - Log.d(Constants.TAG, "starting activity..."); - Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - intent.setAction(action); - - Messenger messenger = new Messenger(new Handler(getMainLooper(), callback)); - - extras.putParcelable(RemoteServiceActivity.EXTRA_MESSENGER, messenger); - intent.putExtras(extras); - - startActivity(intent); - - // lock current thread for user input - try { - userInputLock.wait(); - } catch (InterruptedException e) { - Log.e(Constants.TAG, "CryptoService", e); - } - } - } +// protected void pauseAndStartUserInteraction(String action, BaseCallback callback, Bundle extras) { +// synchronized (userInputLock) { +// mThreadPool.pause(); +// +// Log.d(Constants.TAG, "starting activity..."); +// Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class); +// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); +// intent.setAction(action); +// +// Messenger messenger = new Messenger(new Handler(getMainLooper(), callback)); +// +// extras.putParcelable(RemoteServiceActivity.EXTRA_MESSENGER, messenger); +// intent.putExtras(extras); +// +// startActivity(intent); +// +// // lock current thread for user input +// try { +// userInputLock.wait(); +// } catch (InterruptedException e) { +// Log.e(Constants.TAG, "CryptoService", e); +// } +// } +// } /** * Retrieves AppSettings from database for the application calling this remote service @@ -216,59 +216,59 @@ public abstract class RemoteService extends Service { return null; } - class RegisterActivityCallback extends BaseCallback { - public static final String PACKAGE_NAME = "package_name"; - - private boolean allowed = false; - private String packageName; - - public boolean isAllowed() { - return allowed; - } - - public String getPackageName() { - return packageName; - } - - @Override - public boolean handleMessage(Message msg) { - if (msg.arg1 == OKAY) { - allowed = true; - packageName = msg.getData().getString(PACKAGE_NAME); - - // resume threads - try { - if (isPackageAllowed(packageName)) { - synchronized (userInputLock) { - userInputLock.notifyAll(); - } - mThreadPool.resume(); - } else { - // Should not happen! - Log.e(Constants.TAG, "Should not happen! Emergency shutdown!"); - mThreadPool.shutdownNow(); - } - } catch (WrongPackageSignatureException e) { - Log.e(Constants.TAG, e.getMessage()); - - Bundle extras = new Bundle(); - extras.putString(RemoteServiceActivity.EXTRA_ERROR_MESSAGE, - getString(R.string.api_error_wrong_signature)); - pauseAndStartUserInteraction(RemoteServiceActivity.ACTION_ERROR_MESSAGE, null, - extras); - } - } else { - allowed = false; - - synchronized (userInputLock) { - userInputLock.notifyAll(); - } - mThreadPool.resume(); - } - return true; - } - - } +// class RegisterActivityCallback extends BaseCallback { +// public static final String PACKAGE_NAME = "package_name"; +// +// private boolean allowed = false; +// private String packageName; +// +// public boolean isAllowed() { +// return allowed; +// } +// +// public String getPackageName() { +// return packageName; +// } +// +// @Override +// public boolean handleMessage(Message msg) { +// if (msg.arg1 == OKAY) { +// allowed = true; +// packageName = msg.getData().getString(PACKAGE_NAME); +// +// // resume threads +// try { +// if (isPackageAllowed(packageName)) { +// synchronized (userInputLock) { +// userInputLock.notifyAll(); +// } +// mThreadPool.resume(); +// } else { +// // Should not happen! +// Log.e(Constants.TAG, "Should not happen! Emergency shutdown!"); +// mThreadPool.shutdownNow(); +// } +// } catch (WrongPackageSignatureException e) { +// Log.e(Constants.TAG, e.getMessage()); +// +// Bundle extras = new Bundle(); +// extras.putString(RemoteServiceActivity.EXTRA_ERROR_MESSAGE, +// getString(R.string.api_error_wrong_signature)); +// pauseAndStartUserInteraction(RemoteServiceActivity.ACTION_ERROR_MESSAGE, null, +// extras); +// } +// } else { +// allowed = false; +// +// synchronized (userInputLock) { +// userInputLock.notifyAll(); +// } +// mThreadPool.resume(); +// } +// return true; +// } +// +// } /** * Checks if process that binds to this service (i.e. the package name corresponding to the diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java index 8f5b74650..af8e3ade8 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/service/remote/RemoteServiceActivity.java @@ -22,7 +22,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.Messenger; -import android.os.RemoteException; import android.support.v7.app.ActionBarActivity; import android.view.View; @@ -64,17 +63,11 @@ public class RemoteServiceActivity extends ActionBarActivity { // error message public static final String EXTRA_ERROR_MESSAGE = "error_message"; - private Messenger mMessenger; - // register view private AppSettingsFragment mSettingsFragment; // select pub keys view private SelectPublicKeyFragment mSelectFragment; - // has the user clicked one of the buttons - // or do we need to handle the callback in onStop() - private boolean finishHandled; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -82,32 +75,12 @@ public class RemoteServiceActivity extends ActionBarActivity { handleActions(getIntent(), savedInstanceState); } - @Override - protected void onStop() { - super.onStop(); - - if (!finishHandled && mMessenger != null) { - Message msg = Message.obtain(); - msg.arg1 = RemoteService.RegisterActivityCallback.CANCEL; - try { - mMessenger.send(msg); - } catch (RemoteException e) { - Log.e(Constants.TAG, "CryptoServiceActivity", e); - } - } - } - protected void handleActions(Intent intent, Bundle savedInstanceState) { - finishHandled = false; String action = intent.getAction(); final Bundle extras = intent.getExtras(); - mMessenger = extras.getParcelable(EXTRA_MESSENGER); - /** - * com.android.crypto actions - */ if (ACTION_REGISTER.equals(action)) { final String packageName = extras.getString(EXTRA_PACKAGE_NAME); final byte[] packageSignature = extras.getByteArray(EXTRA_PACKAGE_SIGNATURE); @@ -127,37 +100,21 @@ public class RemoteServiceActivity extends ActionBarActivity { ProviderHelper.insertApiApp(RemoteServiceActivity.this, mSettingsFragment.getAppSettings()); - Message msg = Message.obtain(); - msg.arg1 = RemoteService.RegisterActivityCallback.OKAY; - Bundle data = new Bundle(); - data.putString(RemoteService.RegisterActivityCallback.PACKAGE_NAME, - packageName); - msg.setData(data); - try { - mMessenger.send(msg); - } catch (RemoteException e) { - Log.e(Constants.TAG, "CryptoServiceActivity", e); - } + // give params through for new service call + Bundle oldParams = extras.getBundle(OpenPgpConstants.PI_RESULT_PARAMS); - finishHandled = true; - finish(); + Intent finishIntent = new Intent(); + finishIntent.putExtra(OpenPgpConstants.PI_RESULT_PARAMS, oldParams); + RemoteServiceActivity.this.setResult(RESULT_OK, finishIntent); + RemoteServiceActivity.this.finish(); } } }, R.string.api_register_disallow, new View.OnClickListener() { @Override public void onClick(View v) { // Disallow - - Message msg = Message.obtain(); - msg.arg1 = RemoteService.RegisterActivityCallback.CANCEL; - try { - mMessenger.send(msg); - } catch (RemoteException e) { - Log.e(Constants.TAG, "CryptoServiceActivity", e); - } - - finishHandled = true; - finish(); + RemoteServiceActivity.this.setResult(RESULT_CANCELED); + RemoteServiceActivity.this.finish(); } } ); @@ -216,15 +173,15 @@ public class RemoteServiceActivity extends ActionBarActivity { Intent finishIntent = new Intent(); finishIntent.putExtra(OpenPgpConstants.PI_RESULT_PARAMS, params); - setResult(RESULT_OK, finishIntent); - finish(); + RemoteServiceActivity.this.setResult(RESULT_OK, finishIntent); + RemoteServiceActivity.this.finish(); } }, R.string.btn_do_not_save, new View.OnClickListener() { @Override public void onClick(View v) { // cancel - setResult(RESULT_CANCELED); - finish(); + RemoteServiceActivity.this.setResult(RESULT_CANCELED); + RemoteServiceActivity.this.finish(); } } ); @@ -265,8 +222,8 @@ public class RemoteServiceActivity extends ActionBarActivity { @Override public void onClick(View v) { - setResult(RESULT_OK); - finish(); + RemoteServiceActivity.this.setResult(RESULT_OK); + RemoteServiceActivity.this.finish(); } }); @@ -276,7 +233,7 @@ public class RemoteServiceActivity extends ActionBarActivity { HtmlTextView textView = (HtmlTextView) findViewById(R.id.api_app_error_message_text); textView.setHtmlFromString(text); } else { - Log.e(Constants.TAG, "Wrong action!"); + Log.e(Constants.TAG, "Action does not exist!"); setResult(RESULT_CANCELED); finish(); }