diff options
author | Dominik <dominik@dominikschuermann.de> | 2012-11-16 02:34:21 +0100 |
---|---|---|
committer | Dominik <dominik@dominikschuermann.de> | 2012-11-16 02:34:21 +0100 |
commit | bbddc4c56dbb71c536aac736d197bcc8e49f6769 (patch) | |
tree | b4f255f9108495e754baee5e1ebe6ce5d2c40109 /org_apg/src/org/thialfihar/android/apg/helper | |
parent | 0f3164c5b58f1f368a2710e0c653bb911d74df6d (diff) | |
download | open-keychain-bbddc4c56dbb71c536aac736d197bcc8e49f6769.tar.gz open-keychain-bbddc4c56dbb71c536aac736d197bcc8e49f6769.tar.bz2 open-keychain-bbddc4c56dbb71c536aac736d197bcc8e49f6769.zip |
implemented security model
Diffstat (limited to 'org_apg/src/org/thialfihar/android/apg/helper')
-rw-r--r-- | org_apg/src/org/thialfihar/android/apg/helper/OtherHelper.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/org_apg/src/org/thialfihar/android/apg/helper/OtherHelper.java b/org_apg/src/org/thialfihar/android/apg/helper/OtherHelper.java index 531ae20fb..7d618406b 100644 --- a/org_apg/src/org/thialfihar/android/apg/helper/OtherHelper.java +++ b/org_apg/src/org/thialfihar/android/apg/helper/OtherHelper.java @@ -23,13 +23,17 @@ import java.util.Iterator; import java.util.Set; import org.thialfihar.android.apg.Constants; +import org.thialfihar.android.apg.R; import org.thialfihar.android.apg.util.Log; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockFragmentActivity; +import android.app.Activity; import android.content.Context; +import android.content.pm.PackageManager; import android.os.Bundle; +import android.widget.Toast; public class OtherHelper { @@ -118,6 +122,45 @@ public class OtherHelper { } /** + * Check if the calling package has the needed permission to invoke an intent with specific + * restricted actions. + * + * If pkgName is null, this will also deny the use of the given action + * + * @param activity + * @param pkgName + * @param permName + * @param action + * @param restrictedActions + */ + public static void checkPackagePermissionForActions(Activity activity, String pkgName, + String permName, String action, String[] restrictedActions) { + if (action != null) { + PackageManager pkgManager = activity.getPackageManager(); + + for (int i = 0; i < restrictedActions.length; i++) { + if (restrictedActions[i].equals(action)) { + if (pkgName != null + && pkgManager.checkPermission(permName, pkgName) == PackageManager.PERMISSION_GRANTED) { + Log.d(Constants.TAG, pkgName + " has permission " + permName + ". Action " + + action + " was granted!"); + } else { + String error = pkgName + " does NOT have permission " + permName + ". Action " + + action + " was NOT granted!"; + Log.e(Constants.TAG, error); + Toast.makeText(activity, activity.getString(R.string.errorMessage, error), + Toast.LENGTH_LONG).show(); + + // end activity + activity.setResult(Activity.RESULT_CANCELED, null); + activity.finish(); + } + } + } + } + } + + /** * Splits userId string into naming part and email part * * @param userId |