Redifine Service callbacks

This commit is contained in:
Dominik Schürmann 2013-07-25 16:25:20 +02:00
parent 14350679d1
commit 7cca7b1ffa
8 changed files with 147 additions and 47 deletions

View File

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="3dip" >
<TextView
android:id="@+id/register_crypto_consumer_select_key"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="Select key"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/register_crypto_consumer_select_key_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TD Select priv key" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/asciiArmour"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/label_asciiArmour" />
</LinearLayout>
<LinearLayout
android:id="@+id/register_crypto_consumer_register_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="3dip" >
<TextView
android:id="@+id/register_crypto_consumer_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Package TODO requests permanent access to OpenPGP Keychain\&apos;s API. Allow permanent access?"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="@+id/register_crypto_consumer_register_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="3dip" >
<Button
android:id="@+id/register_crypto_consumer_disallow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Disallow access" />
<Button
android:id="@+id/register_crypto_consumer_allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Allow access" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/register_crypto_consumer_edit_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="3dip" >
<Button
android:id="@+id/register_crypto_consumer_disallow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Revoke access" />
<Button
android:id="@+id/register_crypto_consumer_allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
</LinearLayout>
</LinearLayout>

View File

@ -22,7 +22,6 @@
android:orientation="vertical" > android:orientation="vertical" >
<ScrollView <ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:fillViewport="true" > android:fillViewport="true" >

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register?" />
<Button
android:id="@+id/register_crypto_consumer_allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Allow access" />
<Button
android:id="@+id/register_crypto_consumer_disallow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Disallow" />
</LinearLayout>

View File

@ -19,7 +19,7 @@ public class CryptoConsumersActivity extends SherlockFragmentActivity {
mActionBar = getSupportActionBar(); mActionBar = getSupportActionBar();
setContentView(R.layout.crypto_consumers_activity); setContentView(R.layout.crypto_consumer_list_activity);
mActionBar.setDisplayShowTitleEnabled(true); mActionBar.setDisplayShowTitleEnabled(true);
mActionBar.setDisplayHomeAsUpEnabled(true); mActionBar.setDisplayHomeAsUpEnabled(true);

View File

@ -263,7 +263,7 @@ public class CryptoService extends Service {
private final IServiceActivityCallback.Stub mBinderServiceActivity = new IServiceActivityCallback.Stub() { private final IServiceActivityCallback.Stub mBinderServiceActivity = new IServiceActivityCallback.Stub() {
@Override @Override
public void register(boolean success, String packageName) throws RemoteException { public void onRegistered(boolean success, String packageName) throws RemoteException {
if (success) { if (success) {
// resume threads // resume threads
@ -280,7 +280,7 @@ public class CryptoService extends Service {
} }
@Override @Override
public void cachePassphrase(boolean success, String passphrase) throws RemoteException { public void onCachedPassphrase(boolean success) throws RemoteException {
} }
@ -355,8 +355,6 @@ public class CryptoService extends Service {
Log.d(Constants.TAG, "starting activity..."); Log.d(Constants.TAG, "starting activity...");
Intent intent = new Intent(getBaseContext(), ServiceActivity.class); Intent intent = new Intent(getBaseContext(), ServiceActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
intent.setAction(action); intent.setAction(action);
if (extras != null) { if (extras != null) {
intent.putExtras(extras); intent.putExtras(extras);

View File

@ -19,10 +19,8 @@ package org.sufficientlysecure.keychain.remote_api;
interface IServiceActivityCallback { interface IServiceActivityCallback {
oneway void onRegistered(in boolean success, in String packageName);
oneway void register(in boolean success, in String packageName); oneway void onCachedPassphrase(in boolean success);
oneway void cachePassphrase(in boolean success, in String passphrase);
} }

View File

@ -16,6 +16,8 @@
package org.sufficientlysecure.keychain.remote_api; package org.sufficientlysecure.keychain.remote_api;
import java.util.ArrayList;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.remote_api.IServiceActivityCallback; import org.sufficientlysecure.keychain.remote_api.IServiceActivityCallback;
@ -35,30 +37,32 @@ import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Message; import android.os.Message;
import android.os.Messenger; import android.os.Messenger;
import android.os.RemoteException;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout;
public class ServiceActivity extends SherlockFragmentActivity { public class ServiceActivity extends SherlockFragmentActivity {
public static final String ACTION_REGISTER = "org.sufficientlysecure.keychain.REGISTER"; public static final String ACTION_REGISTER = "org.sufficientlysecure.keychain.remote_api.REGISTER";
public static final String ACTION_CACHE_PASSPHRASE = "org.sufficientlysecure.keychain.CRYPTO_CACHE_PASSPHRASE"; public static final String ACTION_CACHE_PASSPHRASE = "org.sufficientlysecure.keychain.remote_api.CRYPTO_CACHE_PASSPHRASE";
public static final String EXTRA_SECRET_KEY_ID = "secretKeyId"; public static final String EXTRA_SECRET_KEY_ID = "secretKeyId";
public static final String EXTRA_PACKAGE_NAME = "packageName"; public static final String EXTRA_PACKAGE_NAME = "packageName";
private IServiceActivityCallback mService; private IServiceActivityCallback mServiceCallback;
private boolean mServiceBound; private boolean mServiceBound;
private ServiceConnection mServiceActivityConnection = new ServiceConnection() { private ServiceConnection mServiceActivityConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
mService = IServiceActivityCallback.Stub.asInterface(service); mServiceCallback = IServiceActivityCallback.Stub.asInterface(service);
Log.d(Constants.TAG, "connected to ICryptoServiceActivity"); Log.d(Constants.TAG, "connected to ICryptoServiceActivity");
mServiceBound = true; mServiceBound = true;
} }
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
mService = null; mServiceCallback = null;
Log.d(Constants.TAG, "disconnected from ICryptoServiceActivity"); Log.d(Constants.TAG, "disconnected from ICryptoServiceActivity");
mServiceBound = false; mServiceBound = false;
} }
@ -70,7 +74,7 @@ public class ServiceActivity extends SherlockFragmentActivity {
* @return * @return
*/ */
public boolean bindToService() { public boolean bindToService() {
if (mService == null && !mServiceBound) { // if not already connected if (mServiceCallback == null && !mServiceBound) { // if not already connected
try { try {
Log.d(Constants.TAG, "not bound yet"); Log.d(Constants.TAG, "not bound yet");
@ -129,7 +133,20 @@ public class ServiceActivity extends SherlockFragmentActivity {
if (ACTION_REGISTER.equals(action)) { if (ACTION_REGISTER.equals(action)) {
final String packageName = extras.getString(EXTRA_PACKAGE_NAME); final String packageName = extras.getString(EXTRA_PACKAGE_NAME);
setContentView(R.layout.register_crypto_consumer_activity); setContentView(R.layout.crypto_consumer_register_activity);
LinearLayout layoutRegister = (LinearLayout) findViewById(R.id.register_crypto_consumer_register_layout);
LinearLayout layoutEdit = (LinearLayout) findViewById(R.id.register_crypto_consumer_edit_layout);
// if already registered show edit buttons
ArrayList<String> allowedPkgs = ProviderHelper.getCryptoConsumers(this);
if (allowedPkgs.contains(packageName)) {
Log.d(Constants.TAG, "Package is allowed! packageName: " + packageName);
layoutRegister.setVisibility(View.GONE);
layoutEdit.setVisibility(View.VISIBLE);
} else {
layoutRegister.setVisibility(View.VISIBLE);
layoutEdit.setVisibility(View.GONE);
}
Button allowButton = (Button) findViewById(R.id.register_crypto_consumer_allow); Button allowButton = (Button) findViewById(R.id.register_crypto_consumer_allow);
Button disallowButton = (Button) findViewById(R.id.register_crypto_consumer_disallow); Button disallowButton = (Button) findViewById(R.id.register_crypto_consumer_disallow);
@ -141,7 +158,11 @@ public class ServiceActivity extends SherlockFragmentActivity {
ProviderHelper.addCryptoConsumer(ServiceActivity.this, packageName); ProviderHelper.addCryptoConsumer(ServiceActivity.this, packageName);
// Intent data = new Intent(); // Intent data = new Intent();
setResult(RESULT_OK); try {
mServiceCallback.onRegistered(true, packageName);
} catch (RemoteException e) {
Log.e(Constants.TAG, "ServiceActivity");
}
finish(); finish();
} }
}); });
@ -150,7 +171,11 @@ public class ServiceActivity extends SherlockFragmentActivity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
setResult(RESULT_CANCELED); try {
mServiceCallback.onRegistered(false, packageName);
} catch (RemoteException e) {
Log.e(Constants.TAG, "ServiceActivity");
}
finish(); finish();
} }
}); });
@ -160,7 +185,6 @@ public class ServiceActivity extends SherlockFragmentActivity {
showPassphraseDialog(secretKeyId); showPassphraseDialog(secretKeyId);
} else { } else {
Log.e(Constants.TAG, "Wrong action!"); Log.e(Constants.TAG, "Wrong action!");
setResult(RESULT_CANCELED);
finish(); finish();
} }
} }
@ -176,7 +200,11 @@ public class ServiceActivity extends SherlockFragmentActivity {
@Override @Override
public void handleMessage(Message message) { public void handleMessage(Message message) {
if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) { if (message.what == PassphraseDialogFragment.MESSAGE_OKAY) {
setResult(RESULT_OK); try {
mServiceCallback.onCachedPassphrase(true);
} catch (RemoteException e) {
Log.e(Constants.TAG, "ServiceActivity");
}
finish(); finish();
} }
} }