From 918bab3a4e7b582dce5b994e115ca8de37da4ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 17 Jun 2013 16:05:39 +0200 Subject: Rename foir clarification --- OpenPGP-Keychain/AndroidManifest.xml | 2 +- .../keychain/crypto_provider/CryptoActivity.java | 197 --------------------- .../keychain/crypto_provider/CryptoService.java | 14 +- .../crypto_provider/ICryptoServiceActivity.aidl | 28 --- .../crypto_provider/IServiceActivityCallback.aidl | 28 +++ .../keychain/crypto_provider/ServiceActivity.java | 197 +++++++++++++++++++++ 6 files changed, 233 insertions(+), 233 deletions(-) delete mode 100644 OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoActivity.java delete mode 100644 OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ICryptoServiceActivity.aidl create mode 100644 OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/IServiceActivityCallback.aidl create mode 100644 OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ServiceActivity.java diff --git a/OpenPGP-Keychain/AndroidManifest.xml b/OpenPGP-Keychain/AndroidManifest.xml index 0b8ed515e..7796f4446 100644 --- a/OpenPGP-Keychain/AndroidManifest.xml +++ b/OpenPGP-Keychain/AndroidManifest.xml @@ -478,7 +478,7 @@ - + - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.sufficientlysecure.keychain.crypto_provider; - -import org.sufficientlysecure.keychain.Constants; -import org.sufficientlysecure.keychain.R; -import org.sufficientlysecure.keychain.helper.PgpMain; -import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; -import org.sufficientlysecure.keychain.util.Log; - -import com.actionbarsherlock.app.SherlockFragmentActivity; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.ServiceConnection; -import android.os.Bundle; -import android.os.Handler; -import android.os.IBinder; -import android.os.Message; -import android.os.Messenger; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; - -public class CryptoActivity extends SherlockFragmentActivity { - - public static final String ACTION_REGISTER = "org.sufficientlysecure.keychain.REGISTER"; - public static final String ACTION_CACHE_PASSPHRASE = "org.sufficientlysecure.keychain.CRYPTO_CACHE_PASSPHRASE"; - - public static final String EXTRA_SECRET_KEY_ID = "secretKeyId"; - public static final String EXTRA_PACKAGE_NAME = "packageName"; - - private ICryptoServiceActivity mService; - private boolean mServiceBound; - - private ServiceConnection mServiceActivityConnection = new ServiceConnection() { - public void onServiceConnected(ComponentName name, IBinder service) { - mService = ICryptoServiceActivity.Stub.asInterface(service); - Log.d(Constants.TAG, "connected to ICryptoServiceActivity"); - mServiceBound = true; - } - - public void onServiceDisconnected(ComponentName name) { - mService = null; - Log.d(Constants.TAG, "disconnected from ICryptoServiceActivity"); - mServiceBound = false; - } - }; - - /** - * If not already bound, bind! - * - * @return - */ - public boolean bindToService() { - if (mService == null && !mServiceBound) { // if not already connected - try { - Log.d(Constants.TAG, "not bound yet"); - - Intent serviceIntent = new Intent(); - serviceIntent.setAction("org.openintents.crypto.ICryptoService"); - bindService(serviceIntent, mServiceActivityConnection, Context.BIND_AUTO_CREATE); - - return true; - } catch (Exception e) { - Log.d(Constants.TAG, "Exception", e); - return false; - } - } else { // already connected - Log.d(Constants.TAG, "already bound... "); - return true; - } - } - - public void unbindFromService() { - unbindService(mServiceActivityConnection); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - Log.d(Constants.TAG, "onCreate…"); - - // bind to our own crypto service - bindToService(); - - handleActions(getIntent()); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - - // unbind from our crypto service - if (mServiceActivityConnection != null) { - unbindFromService(); - } - } - - protected void handleActions(Intent intent) { - String action = intent.getAction(); - Bundle extras = intent.getExtras(); - - if (extras == null) { - extras = new Bundle(); - } - - /** - * com.android.crypto actions - */ - if (ACTION_REGISTER.equals(action)) { - final String packageName = extras.getString(EXTRA_PACKAGE_NAME); - - setContentView(R.layout.register_crypto_consumer_activity); - - Button allowButton = (Button) findViewById(R.id.register_crypto_consumer_allow); - Button disallowButton = (Button) findViewById(R.id.register_crypto_consumer_disallow); - - allowButton.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - // ProviderHelper.addCryptoConsumer(RegisterActivity.this, callingPackageName); - // Intent data = new Intent(); - - setResult(RESULT_OK); - finish(); - } - }); - - disallowButton.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - setResult(RESULT_CANCELED); - finish(); - } - }); - } else if (ACTION_CACHE_PASSPHRASE.equals(action)) { - long secretKeyId = extras.getLong(EXTRA_SECRET_KEY_ID); - - showPassphraseDialog(secretKeyId); - } else { - Log.e(Constants.TAG, "Wrong action!"); - setResult(RESULT_CANCELED); - finish(); - } - } - - /** - * Shows passphrase dialog to cache a new passphrase the user enters for using it later for - * encryption. Based on mSecretKeyId it asks for a passphrase to open a private key or it asks - * for a symmetric passphrase - */ - private void showPassphraseDialog(long secretKeyId) { - // Message is received after passphrase is cached - Handler returnHandler = new Handler() { - @Override - public void handleMessage(Message message) { - if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { - setResult(RESULT_OK); - finish(); - } - } - }; - - // Create a new Messenger for the communication back - Messenger messenger = new Messenger(returnHandler); - - try { - PassphraseDialogFragment passphraseDialog = PassphraseDialogFragment.newInstance(this, - messenger, secretKeyId); - - passphraseDialog.show(getSupportFragmentManager(), "passphraseDialog"); - } catch (PgpMain.PgpGeneralException e) { - Log.d(Constants.TAG, "No passphrase for this secret key, encrypt directly!"); - // send message to handler to start encryption directly - returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY); - } - } -} diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java index 10eb94c7f..3748ef521 100644 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java @@ -60,7 +60,7 @@ public class CryptoService extends Service { // RemoteCallbackList - public static final String ACTION_SERVICE_ACTIVITY = "org.sufficientlysecure.keychain.crypto_provider.ICryptoServiceActivity"; + public static final String ACTION_SERVICE_ACTIVITY = "org.sufficientlysecure.keychain.crypto_provider.IServiceActivityCallback"; @Override public void onCreate() { @@ -123,8 +123,8 @@ public class CryptoService extends Service { // start passphrase dialog Bundle extras = new Bundle(); - extras.putLong(CryptoActivity.EXTRA_SECRET_KEY_ID, secretKeyId); - pauseQueueAndStartCryptoActivity(CryptoActivity.ACTION_CACHE_PASSPHRASE, extras); + extras.putLong(ServiceActivity.EXTRA_SECRET_KEY_ID, secretKeyId); + pauseQueueAndStartServiceActivity(ServiceActivity.ACTION_CACHE_PASSPHRASE, extras); } // if (signedOnly) { @@ -214,7 +214,7 @@ public class CryptoService extends Service { }; - private final ICryptoServiceActivity.Stub mBinderServiceActivity = new ICryptoServiceActivity.Stub() { + private final IServiceActivityCallback.Stub mBinderServiceActivity = new IServiceActivityCallback.Stub() { @Override public void register(boolean success, String packageName) throws RemoteException { @@ -249,7 +249,7 @@ public class CryptoService extends Service { Log.d(Constants.TAG, "Enqueued runnable…"); } else { Log.e(Constants.TAG, "Not allowed to use service! Starting register with activity!"); - pauseQueueAndStartCryptoActivity(CryptoActivity.ACTION_REGISTER, null); + pauseQueueAndStartServiceActivity(ServiceActivity.ACTION_REGISTER, null); mThreadPool.execute(r); Log.d(Constants.TAG, "Enqueued runnable…"); @@ -286,11 +286,11 @@ public class CryptoService extends Service { return false; } - private void pauseQueueAndStartCryptoActivity(String action, Bundle extras) { + private void pauseQueueAndStartServiceActivity(String action, Bundle extras) { mThreadPool.pause(); Log.d(Constants.TAG, "starting activity..."); - Intent intent = new Intent(getBaseContext(), CryptoActivity.class); + Intent intent = new Intent(getBaseContext(), ServiceActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ICryptoServiceActivity.aidl b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ICryptoServiceActivity.aidl deleted file mode 100644 index 51586cae6..000000000 --- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ICryptoServiceActivity.aidl +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2013 Dominik Schürmann - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.sufficientlysecure.keychain.crypto_provider; - - -interface ICryptoServiceActivity { - - - oneway void register(in boolean success, in String packageName); - - oneway void cachePassphrase(in boolean success, in String passphrase); - - -} \ No newline at end of file diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/IServiceActivityCallback.aidl b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/IServiceActivityCallback.aidl new file mode 100644 index 000000000..61a8da06c --- /dev/null +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/IServiceActivityCallback.aidl @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2013 Dominik Schürmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.sufficientlysecure.keychain.crypto_provider; + + +interface IServiceActivityCallback { + + + oneway void register(in boolean success, in String packageName); + + oneway void cachePassphrase(in boolean success, in String passphrase); + + +} \ No newline at end of file diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ServiceActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ServiceActivity.java new file mode 100644 index 000000000..9f68aab97 --- /dev/null +++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ServiceActivity.java @@ -0,0 +1,197 @@ +/* + * Copyright (C) 2013 Dominik Schürmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.sufficientlysecure.keychain.crypto_provider; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.helper.PgpMain; +import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; +import org.sufficientlysecure.keychain.util.Log; + +import com.actionbarsherlock.app.SherlockFragmentActivity; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.ServiceConnection; +import android.os.Bundle; +import android.os.Handler; +import android.os.IBinder; +import android.os.Message; +import android.os.Messenger; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; + +public class ServiceActivity extends SherlockFragmentActivity { + + public static final String ACTION_REGISTER = "org.sufficientlysecure.keychain.REGISTER"; + public static final String ACTION_CACHE_PASSPHRASE = "org.sufficientlysecure.keychain.CRYPTO_CACHE_PASSPHRASE"; + + public static final String EXTRA_SECRET_KEY_ID = "secretKeyId"; + public static final String EXTRA_PACKAGE_NAME = "packageName"; + + private IServiceActivityCallback mService; + private boolean mServiceBound; + + private ServiceConnection mServiceActivityConnection = new ServiceConnection() { + public void onServiceConnected(ComponentName name, IBinder service) { + mService = IServiceActivityCallback.Stub.asInterface(service); + Log.d(Constants.TAG, "connected to ICryptoServiceActivity"); + mServiceBound = true; + } + + public void onServiceDisconnected(ComponentName name) { + mService = null; + Log.d(Constants.TAG, "disconnected from ICryptoServiceActivity"); + mServiceBound = false; + } + }; + + /** + * If not already bound, bind! + * + * @return + */ + public boolean bindToService() { + if (mService == null && !mServiceBound) { // if not already connected + try { + Log.d(Constants.TAG, "not bound yet"); + + Intent serviceIntent = new Intent(); + serviceIntent.setAction("org.openintents.crypto.ICryptoService"); + bindService(serviceIntent, mServiceActivityConnection, Context.BIND_AUTO_CREATE); + + return true; + } catch (Exception e) { + Log.d(Constants.TAG, "Exception", e); + return false; + } + } else { // already connected + Log.d(Constants.TAG, "already bound... "); + return true; + } + } + + public void unbindFromService() { + unbindService(mServiceActivityConnection); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + Log.d(Constants.TAG, "onCreate…"); + + // bind to our own crypto service + bindToService(); + + handleActions(getIntent()); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + // unbind from our crypto service + if (mServiceActivityConnection != null) { + unbindFromService(); + } + } + + protected void handleActions(Intent intent) { + String action = intent.getAction(); + Bundle extras = intent.getExtras(); + + if (extras == null) { + extras = new Bundle(); + } + + /** + * com.android.crypto actions + */ + if (ACTION_REGISTER.equals(action)) { + final String packageName = extras.getString(EXTRA_PACKAGE_NAME); + + setContentView(R.layout.register_crypto_consumer_activity); + + Button allowButton = (Button) findViewById(R.id.register_crypto_consumer_allow); + Button disallowButton = (Button) findViewById(R.id.register_crypto_consumer_disallow); + + allowButton.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + // ProviderHelper.addCryptoConsumer(RegisterActivity.this, callingPackageName); + // Intent data = new Intent(); + + setResult(RESULT_OK); + finish(); + } + }); + + disallowButton.setOnClickListener(new OnClickListener() { + + @Override + public void onClick(View v) { + setResult(RESULT_CANCELED); + finish(); + } + }); + } else if (ACTION_CACHE_PASSPHRASE.equals(action)) { + long secretKeyId = extras.getLong(EXTRA_SECRET_KEY_ID); + + showPassphraseDialog(secretKeyId); + } else { + Log.e(Constants.TAG, "Wrong action!"); + setResult(RESULT_CANCELED); + finish(); + } + } + + /** + * Shows passphrase dialog to cache a new passphrase the user enters for using it later for + * encryption. Based on mSecretKeyId it asks for a passphrase to open a private key or it asks + * for a symmetric passphrase + */ + private void showPassphraseDialog(long secretKeyId) { + // Message is received after passphrase is cached + Handler returnHandler = new Handler() { + @Override + public void handleMessage(Message message) { + if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { + setResult(RESULT_OK); + finish(); + } + } + }; + + // Create a new Messenger for the communication back + Messenger messenger = new Messenger(returnHandler); + + try { + PassphraseDialogFragment passphraseDialog = PassphraseDialogFragment.newInstance(this, + messenger, secretKeyId); + + passphraseDialog.show(getSupportFragmentManager(), "passphraseDialog"); + } catch (PgpMain.PgpGeneralException e) { + Log.d(Constants.TAG, "No passphrase for this secret key, encrypt directly!"); + // send message to handler to start encryption directly + returnHandler.sendEmptyMessage(PassphraseDialogFragment.MESSAGE_OKAY); + } + } +} -- cgit v1.2.3