mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
Synchronizing methods in ApgKeyService
This commit is contained in:
parent
275bcc443e
commit
b83d82146b
@ -32,7 +32,7 @@ import android.os.RemoteException;
|
|||||||
/**
|
/**
|
||||||
* TODO:
|
* TODO:
|
||||||
*
|
*
|
||||||
* - is this service thread safe? Probably not!
|
* - is this service thread safe?
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ApgKeyService extends Service {
|
public class ApgKeyService extends Service {
|
||||||
@ -56,6 +56,43 @@ public class ApgKeyService extends Service {
|
|||||||
return mBinder;
|
return mBinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronized implementation of getPublicKeyRings
|
||||||
|
*/
|
||||||
|
private synchronized void getPublicKeyRingsSafe(long[] masterKeyIds,
|
||||||
|
boolean asAsciiArmoredStringArray, IApgGetKeyringsHandler handler)
|
||||||
|
throws RemoteException {
|
||||||
|
if (asAsciiArmoredStringArray) {
|
||||||
|
ArrayList<String> output = ProviderHelper.getPublicKeyRingsAsArmoredString(mContext,
|
||||||
|
masterKeyIds);
|
||||||
|
|
||||||
|
handler.onSuccess(null, output);
|
||||||
|
} else {
|
||||||
|
byte[] outputBytes = ProviderHelper
|
||||||
|
.getPublicKeyRingsAsByteArray(mContext, masterKeyIds);
|
||||||
|
handler.onSuccess(outputBytes, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronized implementation of getSecretKeyRings
|
||||||
|
*/
|
||||||
|
private synchronized void getSecretKeyRingsSafe(long[] masterKeyIds,
|
||||||
|
boolean asAsciiArmoredStringArray, IApgGetKeyringsHandler handler)
|
||||||
|
throws RemoteException {
|
||||||
|
if (asAsciiArmoredStringArray) {
|
||||||
|
ArrayList<String> output = ProviderHelper.getSecretKeyRingsAsArmoredString(mContext,
|
||||||
|
masterKeyIds);
|
||||||
|
|
||||||
|
handler.onSuccess(null, output);
|
||||||
|
} else {
|
||||||
|
byte[] outputBytes = ProviderHelper
|
||||||
|
.getSecretKeyRingsAsByteArray(mContext, masterKeyIds);
|
||||||
|
handler.onSuccess(outputBytes, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the implementation of the interface IApgKeyService. All methods are oneway, meaning
|
* This is the implementation of the interface IApgKeyService. All methods are oneway, meaning
|
||||||
* asynchronous and return to the client using handlers.
|
* asynchronous and return to the client using handlers.
|
||||||
@ -67,32 +104,13 @@ public class ApgKeyService extends Service {
|
|||||||
@Override
|
@Override
|
||||||
public void getPublicKeyRings(long[] masterKeyIds, boolean asAsciiArmoredStringArray,
|
public void getPublicKeyRings(long[] masterKeyIds, boolean asAsciiArmoredStringArray,
|
||||||
IApgGetKeyringsHandler handler) throws RemoteException {
|
IApgGetKeyringsHandler handler) throws RemoteException {
|
||||||
if (asAsciiArmoredStringArray) {
|
getPublicKeyRingsSafe(masterKeyIds, asAsciiArmoredStringArray, handler);
|
||||||
ArrayList<String> output = ProviderHelper.getPublicKeyRingsAsArmoredString(
|
|
||||||
mContext, masterKeyIds);
|
|
||||||
|
|
||||||
handler.onSuccess(null, output);
|
|
||||||
} else {
|
|
||||||
byte[] outputBytes = ProviderHelper.getPublicKeyRingsAsByteArray(mContext,
|
|
||||||
masterKeyIds);
|
|
||||||
handler.onSuccess(outputBytes, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getSecretKeyRings(long[] masterKeyIds, boolean asAsciiArmoredStringArray,
|
public void getSecretKeyRings(long[] masterKeyIds, boolean asAsciiArmoredStringArray,
|
||||||
IApgGetKeyringsHandler handler) throws RemoteException {
|
IApgGetKeyringsHandler handler) throws RemoteException {
|
||||||
if (asAsciiArmoredStringArray) {
|
getSecretKeyRingsSafe(masterKeyIds, asAsciiArmoredStringArray, handler);
|
||||||
ArrayList<String> output = ProviderHelper.getSecretKeyRingsAsArmoredString(
|
|
||||||
mContext, masterKeyIds);
|
|
||||||
|
|
||||||
handler.onSuccess(null, output);
|
|
||||||
} else {
|
|
||||||
byte[] outputBytes = ProviderHelper.getSecretKeyRingsAsByteArray(mContext,
|
|
||||||
masterKeyIds);
|
|
||||||
handler.onSuccess(outputBytes, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user