This commit is contained in:
Dominik Schürmann 2014-02-17 19:50:07 +01:00
parent 89d6dcc996
commit d5824e6740
2 changed files with 2 additions and 140 deletions

View File

@ -460,7 +460,7 @@ public class OpenPgpService extends RemoteService {
return null;
}
// TODO: enqueue in thread pool!!!
// TODO: multi-threading
private final IOpenPgpService.Stub mBinder = new IOpenPgpService.Stub() {
@Override
@ -521,23 +521,6 @@ public class OpenPgpService extends RemoteService {
return getKeyIdsImpl(params);
}
// TODO: old example for checkAndEnqueue!
// @Override
// public void getKeyIds(final String[] userIds, final boolean allowUserInteraction,
// final IOpenPgpKeyIdsCallback callback) throws RemoteException {
//
// final AppSettings settings = getAppSettings();
//
// Runnable r = new Runnable() {
// @Override
// public void run() {
// getKeyIdsSafe(userIds, allowUserInteraction, callback, settings);
// }
// };
//
// checkAndEnqueue(r);
// }
};
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
* Copyright (C) 2013-2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -19,8 +19,6 @@ package org.sufficientlysecure.keychain.service.remote;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.util.OpenPgpConstants;
@ -29,7 +27,6 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.PausableThreadPoolExecutor;
import android.app.PendingIntent;
import android.app.Service;
@ -52,31 +49,10 @@ import android.os.Messenger;
public abstract class RemoteService extends Service {
Context mContext;
private final ArrayBlockingQueue<Runnable> mPoolQueue = new ArrayBlockingQueue<Runnable>(100);
// TODO: Are these parameters okay?
private PausableThreadPoolExecutor mThreadPool = new PausableThreadPoolExecutor(2, 4, 10,
TimeUnit.SECONDS, mPoolQueue);
private final Object userInputLock = new Object();
private static final int PRIVATE_REQUEST_CODE_REGISTER = 651;
private static final int PRIVATE_REQUEST_CODE_ERROR = 652;
/**
* Extends Handler.Callback with OKAY (1), CANCEL (0) variables
*/
private class BaseCallback implements Handler.Callback {
public static final int OKAY = 1;
public static final int CANCEL = 0;
@Override
public boolean handleMessage(Message msg) {
return false;
}
}
public Context getContext() {
return mContext;
}
@ -84,10 +60,8 @@ public abstract class RemoteService extends Service {
protected Bundle isAllowed(Bundle params) {
try {
if (isCallerAllowed(false)) {
// mThreadPool.execute(r);
return null;
// Log.d(Constants.TAG, "Enqueued runnable…");
} else {
String[] callingPackages = getPackageManager().getPackagesForUid(
Binder.getCallingUid());
@ -121,15 +95,7 @@ public abstract class RemoteService extends Service {
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_USER_INTERACTION_REQUIRED);
result.putParcelable(OpenPgpConstants.RESULT_INTENT, pi);
// pauseAndStartUserInteraction(RemoteServiceActivity.ACTION_REGISTER, callback,
// extras);
return result;
// if (callback.isAllowed()) {
// mThreadPool.execute(r);
// Log.d(Constants.TAG, "Enqueued runnable…");
// } else {
// Log.d(Constants.TAG, "User disallowed app!");
// }
}
} catch (WrongPackageSignatureException e) {
Log.e(Constants.TAG, "wrong signature!", e);
@ -147,11 +113,6 @@ public abstract class RemoteService extends Service {
result.putParcelable(OpenPgpConstants.RESULT_INTENT, pi);
return result;
// Bundle extras = new Bundle();
// extras.putString(RemoteServiceActivity.EXTRA_ERROR_MESSAGE,
// getString(R.string.api_error_wrong_signature));
// pauseAndStartUserInteraction(RemoteServiceActivity.ACTION_ERROR_MESSAGE, null, extras);
}
}
@ -165,34 +126,6 @@ public abstract class RemoteService extends Service {
return packageSignature;
}
/**
* 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);
// }
// }
// }
/**
* Retrieves AppSettings from database for the application calling this remote service
*
@ -216,60 +149,6 @@ 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;
// }
//
// }
/**
* Checks if process that binds to this service (i.e. the package name corresponding to the
* process) is in the list of allowed package names.