aboutsummaryrefslogtreecommitdiffstats
path: root/OpenPGP-Keychain/src/org
diff options
context:
space:
mode:
Diffstat (limited to 'OpenPGP-Keychain/src/org')
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java45
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ServiceActivity.java3
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainContract.java4
-rw-r--r--OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainProvider.java9
4 files changed, 43 insertions, 18 deletions
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 3748ef521..a70641b58 100644
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java
+++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/CryptoService.java
@@ -58,8 +58,6 @@ public class CryptoService extends Service {
private ArrayList<String> mAllowedPackages;
- // RemoteCallbackList<IInterface>
-
public static final String ACTION_SERVICE_ACTIVITY = "org.sufficientlysecure.keychain.crypto_provider.IServiceActivityCallback";
@Override
@@ -218,12 +216,13 @@ public class CryptoService extends Service {
@Override
public void register(boolean success, String packageName) throws RemoteException {
+
if (success) {
// reload allowed packages
mAllowedPackages = ProviderHelper.getCryptoConsumers(mContext);
// resume threads
- if (isCallerAllowed()) {
+ if (isPackageAllowed(packageName)) {
mThreadPool.resume();
} else {
// TODO: should not happen?
@@ -248,8 +247,15 @@ 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!");
- pauseQueueAndStartServiceActivity(ServiceActivity.ACTION_REGISTER, null);
+ String[] callingPackages = getPackageManager()
+ .getPackagesForUid(Binder.getCallingUid());
+
+ Log.e(Constants.TAG, "Not allowed to use service! Starting activity for registration!");
+ Bundle extras = new Bundle();
+ // TODO: currently simply uses first entry
+ extras.putString(ServiceActivity.EXTRA_PACKAGE_NAME, callingPackages[0]);
+ pauseQueueAndStartServiceActivity(ServiceActivity.ACTION_REGISTER, extras);
+
mThreadPool.execute(r);
Log.d(Constants.TAG, "Enqueued runnable…");
@@ -268,24 +274,33 @@ public class CryptoService extends Service {
// is calling package allowed to use this service?
for (int i = 0; i < callingPackages.length; i++) {
String currentPkg = callingPackages[i];
- Log.d(Constants.TAG, "Caller packageName: " + currentPkg);
-
- // check if package is allowed to use our service
- if (mAllowedPackages.contains(currentPkg)) {
- Log.d(Constants.TAG, "Caller is allowed! packageName: " + currentPkg);
-
- return true;
- } else if (Constants.PACKAGE_NAME.equals(currentPkg)) {
- Log.d(Constants.TAG, "Caller is OpenPGP Keychain! -> allowed!");
+ if (isPackageAllowed(currentPkg)) {
return true;
}
}
-
+
Log.d(Constants.TAG, "Caller is NOT allowed!");
return false;
}
+ private boolean isPackageAllowed(String packageName) {
+ Log.d(Constants.TAG, "packageName: " + packageName);
+
+ // check if package is allowed to use our service
+ if (mAllowedPackages.contains(packageName)) {
+ Log.d(Constants.TAG, "Package is allowed! packageName: " + packageName);
+
+ return true;
+ } else if (Constants.PACKAGE_NAME.equals(packageName)) {
+ Log.d(Constants.TAG, "Package is OpenPGP Keychain! -> allowed!");
+
+ return true;
+ }
+
+ return false;
+ }
+
private void pauseQueueAndStartServiceActivity(String action, Bundle extras) {
mThreadPool.pause();
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ServiceActivity.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ServiceActivity.java
index 9f68aab97..7efce85c7 100644
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ServiceActivity.java
+++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/crypto_provider/ServiceActivity.java
@@ -19,6 +19,7 @@ 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.provider.ProviderHelper;
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
import org.sufficientlysecure.keychain.util.Log;
@@ -136,7 +137,7 @@ public class ServiceActivity extends SherlockFragmentActivity {
@Override
public void onClick(View v) {
- // ProviderHelper.addCryptoConsumer(RegisterActivity.this, callingPackageName);
+ ProviderHelper.addCryptoConsumer(ServiceActivity.this, packageName);
// Intent data = new Intent();
setResult(RESULT_OK);
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainContract.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainContract.java
index 46928c6fa..776d1bfb9 100644
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainContract.java
+++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainContract.java
@@ -222,6 +222,10 @@ public class KeychainContract {
/** Use if a single item is returned */
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.crypto_consumers";
+
+ public static Uri buildIdUri(String rowId) {
+ return CONTENT_URI.buildUpon().appendPath(rowId).build();
+ }
}
public static class DataStream {
diff --git a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainProvider.java b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainProvider.java
index 49286b9ce..70be38e21 100644
--- a/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainProvider.java
+++ b/OpenPGP-Keychain/src/org/sufficientlysecure/keychain/provider/KeychainProvider.java
@@ -600,10 +600,10 @@ public class KeychainProvider extends ContentProvider {
qb.appendWhereEscapeString(uri.getLastPathSegment());
break;
-
+
case CRYPTO_CONSUMERS:
qb.setTables(Tables.CRYPTO_CONSUMERS);
-
+
break;
default:
@@ -686,6 +686,11 @@ public class KeychainProvider extends ContentProvider {
rowUri = UserIds.buildSecretUserIdsUri(Long.toString(rowId));
break;
+ case CRYPTO_CONSUMERS:
+ rowId = db.insertOrThrow(Tables.CRYPTO_CONSUMERS, null, values);
+ rowUri = CryptoConsumers.buildIdUri(Long.toString(rowId));
+
+ break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}