mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
cleanup
This commit is contained in:
parent
89d6dcc996
commit
d5824e6740
@ -460,7 +460,7 @@ public class OpenPgpService extends RemoteService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: enqueue in thread pool!!!
|
// TODO: multi-threading
|
||||||
private final IOpenPgpService.Stub mBinder = new IOpenPgpService.Stub() {
|
private final IOpenPgpService.Stub mBinder = new IOpenPgpService.Stub() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -521,23 +521,6 @@ public class OpenPgpService extends RemoteService {
|
|||||||
return getKeyIdsImpl(params);
|
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
|
@Override
|
||||||
|
@ -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
|
* 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
|
* 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.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.ArrayBlockingQueue;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.openintents.openpgp.OpenPgpError;
|
import org.openintents.openpgp.OpenPgpError;
|
||||||
import org.openintents.openpgp.util.OpenPgpConstants;
|
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.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.PausableThreadPoolExecutor;
|
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
@ -52,31 +49,10 @@ import android.os.Messenger;
|
|||||||
public abstract class RemoteService extends Service {
|
public abstract class RemoteService extends Service {
|
||||||
Context mContext;
|
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_REGISTER = 651;
|
||||||
private static final int PRIVATE_REQUEST_CODE_ERROR = 652;
|
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() {
|
public Context getContext() {
|
||||||
return mContext;
|
return mContext;
|
||||||
}
|
}
|
||||||
@ -84,10 +60,8 @@ public abstract class RemoteService extends Service {
|
|||||||
protected Bundle isAllowed(Bundle params) {
|
protected Bundle isAllowed(Bundle params) {
|
||||||
try {
|
try {
|
||||||
if (isCallerAllowed(false)) {
|
if (isCallerAllowed(false)) {
|
||||||
// mThreadPool.execute(r);
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
// Log.d(Constants.TAG, "Enqueued runnable…");
|
|
||||||
} else {
|
} else {
|
||||||
String[] callingPackages = getPackageManager().getPackagesForUid(
|
String[] callingPackages = getPackageManager().getPackagesForUid(
|
||||||
Binder.getCallingUid());
|
Binder.getCallingUid());
|
||||||
@ -121,15 +95,7 @@ public abstract class RemoteService extends Service {
|
|||||||
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_USER_INTERACTION_REQUIRED);
|
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_USER_INTERACTION_REQUIRED);
|
||||||
result.putParcelable(OpenPgpConstants.RESULT_INTENT, pi);
|
result.putParcelable(OpenPgpConstants.RESULT_INTENT, pi);
|
||||||
|
|
||||||
// pauseAndStartUserInteraction(RemoteServiceActivity.ACTION_REGISTER, callback,
|
|
||||||
// extras);
|
|
||||||
return result;
|
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) {
|
} catch (WrongPackageSignatureException e) {
|
||||||
Log.e(Constants.TAG, "wrong signature!", e);
|
Log.e(Constants.TAG, "wrong signature!", e);
|
||||||
@ -147,11 +113,6 @@ public abstract class RemoteService extends Service {
|
|||||||
result.putParcelable(OpenPgpConstants.RESULT_INTENT, pi);
|
result.putParcelable(OpenPgpConstants.RESULT_INTENT, pi);
|
||||||
|
|
||||||
return result;
|
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;
|
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
|
* Retrieves AppSettings from database for the application calling this remote service
|
||||||
*
|
*
|
||||||
@ -216,60 +149,6 @@ public abstract class RemoteService extends Service {
|
|||||||
return null;
|
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
|
* 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.
|
* process) is in the list of allowed package names.
|
||||||
|
Loading…
Reference in New Issue
Block a user