rename crypto consumers to api apps

This commit is contained in:
Dominik Schürmann 2013-09-05 00:02:48 +02:00
parent fcec7e830c
commit 9a737c7318
11 changed files with 122 additions and 77 deletions

View File

@ -14,14 +14,13 @@
tools:layout="@layout/api_app_settings_fragment" />
<LinearLayout
android:id="@+id/register_crypto_consumer_register_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="3dip" >
<TextView
android:id="@+id/register_crypto_consumer_question"
android:id="@+id/api_register_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TODO: use string"
@ -34,14 +33,14 @@
android:paddingBottom="3dip" >
<Button
android:id="@+id/register_crypto_consumer_disallow"
android:id="@+id/api_register_disallow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/api_register_disallow" />
<Button
android:id="@+id/register_crypto_consumer_allow"
android:id="@+id/api_register_allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"

View File

@ -14,21 +14,20 @@
tools:layout="@layout/api_app_settings_fragment" />
<LinearLayout
android:id="@+id/register_crypto_consumer_edit_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="3dip" >
<Button
android:id="@+id/register_crypto_consumer_disallow"
android:id="@+id/api_app_settings_revoke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/api_settings_revoke" />
<Button
android:id="@+id/register_crypto_consumer_allow"
android:id="@+id/api_app_settings_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"

View File

@ -53,7 +53,7 @@ public class KeychainContract {
String RANK = "rank";
}
interface CryptoConsumersColumns {
interface ApiAppsColumns {
String PACKAGE_NAME = "package_name";
String PRIVATE_KEY_ID = "private_key_id"; // not a database id
String ASCII_ARMOR = "ascii_armor";
@ -87,7 +87,7 @@ public class KeychainContract {
public static final String PATH_USER_IDS = "user_ids";
public static final String PATH_KEYS = "keys";
public static final String BASE_CRYPTO_CONSUMERS = "crypto_consumers";
public static final String BASE_API_APPS = "api_apps";
public static final String PATH_BY_PACKAGE_NAME = "package_name";
public static class KeyRings implements KeyRingsColumns, BaseColumns {
@ -219,15 +219,15 @@ public class KeychainContract {
}
}
public static class CryptoConsumers implements CryptoConsumersColumns, BaseColumns {
public static class ApiApps implements ApiAppsColumns, BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI_INTERNAL.buildUpon()
.appendPath(BASE_CRYPTO_CONSUMERS).build();
.appendPath(BASE_API_APPS).build();
/** Use if multiple items get returned */
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.crypto_consumers";
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.thialfihar.apg.api_apps";
/** 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 final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.thialfihar.apg.api_apps";
public static Uri buildIdUri(String rowId) {
return CONTENT_URI.buildUpon().appendPath(rowId).build();

View File

@ -18,7 +18,7 @@
package org.sufficientlysecure.keychain.provider;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.provider.KeychainContract.CryptoConsumersColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiAppsColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingsColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeysColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIdsColumns;
@ -37,7 +37,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
String KEY_RINGS = "key_rings";
String KEYS = "keys";
String USER_IDS = "user_ids";
String CRYPTO_CONSUMERS = "crypto_consumers";
String API_APPS = "api_apps";
}
private static final String CREATE_KEY_RINGS = "CREATE TABLE IF NOT EXISTS " + Tables.KEY_RINGS
@ -64,14 +64,14 @@ public class KeychainDatabase extends SQLiteOpenHelper {
+ UserIdsColumns.KEY_RING_ROW_ID + ") REFERENCES " + Tables.KEY_RINGS + "("
+ BaseColumns._ID + ") ON DELETE CASCADE)";
private static final String CREATE_CRYPTO_CONSUMERS = "CREATE TABLE IF NOT EXISTS "
+ Tables.CRYPTO_CONSUMERS + " (" + BaseColumns._ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + CryptoConsumersColumns.PACKAGE_NAME
+ " TEXT UNIQUE, " + CryptoConsumersColumns.PRIVATE_KEY_ID + " INT64, "
+ CryptoConsumersColumns.ASCII_ARMOR + " INTEGER, "
+ CryptoConsumersColumns.ENCRYPTION_ALGORITHM + " INTEGER, "
+ CryptoConsumersColumns.HASH_ALORITHM + " INTEGER, "
+ CryptoConsumersColumns.COMPRESSION + " INTEGER)";
private static final String CREATE_API_APPS = "CREATE TABLE IF NOT EXISTS "
+ Tables.API_APPS + " (" + BaseColumns._ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + ApiAppsColumns.PACKAGE_NAME
+ " TEXT UNIQUE, " + ApiAppsColumns.PRIVATE_KEY_ID + " INT64, "
+ ApiAppsColumns.ASCII_ARMOR + " INTEGER, "
+ ApiAppsColumns.ENCRYPTION_ALGORITHM + " INTEGER, "
+ ApiAppsColumns.HASH_ALORITHM + " INTEGER, "
+ ApiAppsColumns.COMPRESSION + " INTEGER)";
KeychainDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
@ -84,7 +84,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
db.execSQL(CREATE_KEY_RINGS);
db.execSQL(CREATE_KEYS);
db.execSQL(CREATE_USER_IDS);
db.execSQL(CREATE_CRYPTO_CONSUMERS);
db.execSQL(CREATE_API_APPS);
}
@Override
@ -112,7 +112,7 @@ public class KeychainDatabase extends SQLiteOpenHelper {
+ " = 1 WHERE " + KeysColumns.IS_MASTER_KEY + "= 1;");
break;
case 4:
db.execSQL(CREATE_CRYPTO_CONSUMERS);
db.execSQL(CREATE_API_APPS);
default:
break;

View File

@ -21,7 +21,7 @@ import java.util.Arrays;
import java.util.HashMap;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.provider.KeychainContract.CryptoConsumers;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingsColumns;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyTypes;
@ -228,10 +228,10 @@ public class KeychainProvider extends ContentProvider {
/**
* Crypto Consumers
*/
matcher.addURI(authority, KeychainContract.BASE_CRYPTO_CONSUMERS, CRYPTO_CONSUMERS);
matcher.addURI(authority, KeychainContract.BASE_CRYPTO_CONSUMERS + "/#",
matcher.addURI(authority, KeychainContract.BASE_API_APPS, CRYPTO_CONSUMERS);
matcher.addURI(authority, KeychainContract.BASE_API_APPS + "/#",
CRYPTO_CONSUMERS_BY_ROW_ID);
matcher.addURI(authority, KeychainContract.BASE_CRYPTO_CONSUMERS + "/"
matcher.addURI(authority, KeychainContract.BASE_API_APPS + "/"
+ KeychainContract.PATH_BY_PACKAGE_NAME + "/*", CRYPTO_CONSUMERS_BY_PACKAGE_NAME);
/**
@ -294,11 +294,11 @@ public class KeychainProvider extends ContentProvider {
return UserIds.CONTENT_ITEM_TYPE;
case CRYPTO_CONSUMERS:
return CryptoConsumers.CONTENT_TYPE;
return ApiApps.CONTENT_TYPE;
case CRYPTO_CONSUMERS_BY_ROW_ID:
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
return CryptoConsumers.CONTENT_ITEM_TYPE;
return ApiApps.CONTENT_ITEM_TYPE;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
@ -609,19 +609,19 @@ public class KeychainProvider extends ContentProvider {
break;
case CRYPTO_CONSUMERS:
qb.setTables(Tables.CRYPTO_CONSUMERS);
qb.setTables(Tables.API_APPS);
break;
case CRYPTO_CONSUMERS_BY_ROW_ID:
qb.setTables(Tables.CRYPTO_CONSUMERS);
qb.setTables(Tables.API_APPS);
qb.appendWhere(BaseColumns._ID + " = ");
qb.appendWhereEscapeString(uri.getLastPathSegment());
break;
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
qb.setTables(Tables.CRYPTO_CONSUMERS);
qb.appendWhere(CryptoConsumers.PACKAGE_NAME + " = ");
qb.setTables(Tables.API_APPS);
qb.appendWhere(ApiApps.PACKAGE_NAME + " = ");
qb.appendWhereEscapeString(uri.getPathSegments().get(2));
break;
@ -712,8 +712,8 @@ public class KeychainProvider extends ContentProvider {
break;
case CRYPTO_CONSUMERS:
rowId = db.insertOrThrow(Tables.CRYPTO_CONSUMERS, null, values);
rowUri = CryptoConsumers.buildIdUri(Long.toString(rowId));
rowId = db.insertOrThrow(Tables.API_APPS, null, values);
rowUri = ApiApps.buildIdUri(Long.toString(rowId));
break;
default:
@ -773,7 +773,7 @@ public class KeychainProvider extends ContentProvider {
break;
case CRYPTO_CONSUMERS_BY_ROW_ID:
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
count = db.delete(Tables.CRYPTO_CONSUMERS,
count = db.delete(Tables.API_APPS,
buildDefaultCryptoConsumersSelection(uri, selection), selectionArgs);
break;
default:
@ -838,7 +838,7 @@ public class KeychainProvider extends ContentProvider {
break;
case CRYPTO_CONSUMERS_BY_ROW_ID:
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
count = db.update(Tables.CRYPTO_CONSUMERS, values,
count = db.update(Tables.API_APPS, values,
buildDefaultCryptoConsumersSelection(uri, selection), selectionArgs);
break;
default:

View File

@ -31,7 +31,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.helper.PgpConversionHelper;
import org.sufficientlysecure.keychain.helper.PgpHelper;
import org.sufficientlysecure.keychain.helper.PgpMain;
import org.sufficientlysecure.keychain.provider.KeychainContract.CryptoConsumers;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
import org.sufficientlysecure.keychain.provider.KeychainContract.UserIds;
@ -719,12 +719,12 @@ public class ProviderHelper {
}
public static ArrayList<String> getCryptoConsumers(Context context) {
Cursor cursor = context.getContentResolver().query(CryptoConsumers.CONTENT_URI, null, null,
Cursor cursor = context.getContentResolver().query(ApiApps.CONTENT_URI, null, null,
null, null);
ArrayList<String> packageNames = new ArrayList<String>();
if (cursor != null) {
int packageNameCol = cursor.getColumnIndex(CryptoConsumers.PACKAGE_NAME);
int packageNameCol = cursor.getColumnIndex(ApiApps.PACKAGE_NAME);
if (cursor.moveToFirst()) {
do {
packageNames.add(cursor.getString(packageNameCol));
@ -741,7 +741,7 @@ public class ProviderHelper {
public static void addCryptoConsumer(Context context, String packageName) {
ContentValues values = new ContentValues();
values.put(CryptoConsumers.PACKAGE_NAME, packageName);
context.getContentResolver().insert(CryptoConsumers.CONTENT_URI, values);
values.put(ApiApps.PACKAGE_NAME, packageName);
context.getContentResolver().insert(ApiApps.CONTENT_URI, values);
}
}

View File

@ -6,6 +6,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.util.Log;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
@ -13,6 +14,8 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
@ -20,22 +23,24 @@ import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class AppSettingsActivity extends SherlockFragmentActivity {
private PackageManager pm;
// model
Uri appUri;
long id;
String packageName;
long keyId;
boolean asciiArmor;
// derived
// model, derived
String appName;
// view
TextView selectedKey;
Button selectKeyButton;
CheckBox asciiArmorCheckBox;
Button saveButton;
Button revokeButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -48,9 +53,26 @@ public class AppSettingsActivity extends SherlockFragmentActivity {
selectedKey = (TextView) findViewById(R.id.api_app_settings_selected_key);
selectKeyButton = (Button) findViewById(R.id.api_app_settings_select_key_button);
asciiArmorCheckBox = (CheckBox) findViewById(R.id.api_app_ascii_armor);
revokeButton = (Button) findViewById(R.id.api_app_settings_revoke);
saveButton = (Button) findViewById(R.id.api_app_settings_save);
revokeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
revokeAccess();
}
});
saveButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
save();
}
});
Intent intent = getIntent();
Uri appUri = intent.getData();
appUri = intent.getData();
if (appUri == null) {
Log.e(Constants.TAG, "Intent data missing. Should be Uri of app!");
finish();
@ -67,7 +89,7 @@ public class AppSettingsActivity extends SherlockFragmentActivity {
if (cur.moveToFirst()) {
do {
packageName = cur.getString(cur
.getColumnIndex(KeychainContract.CryptoConsumers.PACKAGE_NAME));
.getColumnIndex(KeychainContract.ApiApps.PACKAGE_NAME));
// get application name
try {
ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
@ -76,15 +98,35 @@ public class AppSettingsActivity extends SherlockFragmentActivity {
} catch (final NameNotFoundException e) {
appName = getString(R.string.api_unknown_app);
}
// asciiArmor = (cur.getInt(cur
// .getColumnIndex(KeychainContract.CryptoConsumers.ASCII_ARMOR)) == 1);
try {
asciiArmor = (cur.getInt(cur
.getColumnIndexOrThrow(KeychainContract.ApiApps.ASCII_ARMOR)) == 1);
// display values
// asciiArmorCheckBox.setChecked(asciiArmor);
asciiArmorCheckBox.setChecked(asciiArmor);
} catch (IllegalArgumentException e) {
Log.e(Constants.TAG, "AppSettingsActivity", e);
}
} while (cur.moveToNext());
}
}
private void revokeAccess() {
Uri calUri = ContentUris.withAppendedId(appUri, id);
getContentResolver().delete(calUri, null, null);
finish();
}
private void save() {
final ContentValues cv = new ContentValues();
cv.put(KeychainContract.ApiApps.PACKAGE_NAME, packageName);
cv.put(KeychainContract.ApiApps.ASCII_ARMOR, asciiArmor);
// TODO: other parameter
getContentResolver().update(appUri, cv, null, null);
finish();
}
}

View File

@ -60,9 +60,11 @@ public class AppSettingsFragment extends Fragment {
if (advancedSettingsContainer.getVisibility() == View.VISIBLE) {
advancedSettingsContainer.startAnimation(invisibleAnimation);
advancedSettingsContainer.setVisibility(View.INVISIBLE);
advancedSettingsButton.setText(R.string.api_settings_show_advanced);
} else {
advancedSettingsContainer.startAnimation(visibleAnimation);
advancedSettingsContainer.setVisibility(View.VISIBLE);
advancedSettingsButton.setText(R.string.api_settings_hide_advanced);
}
}
});
@ -72,7 +74,6 @@ public class AppSettingsFragment extends Fragment {
@Override
public void onClick(View v) {
selectSecretKey();
}
});
}

View File

@ -17,7 +17,7 @@
package org.sufficientlysecure.keychain.remote_api;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.KeychainContract.CryptoConsumers;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps;
import android.content.Context;
import android.content.pm.ApplicationInfo;
@ -47,7 +47,7 @@ public class RegisteredAppsAdapter extends CursorAdapter {
TextView text1 = (TextView) view.findViewById(android.R.id.text1);
TextView text2 = (TextView) view.findViewById(android.R.id.text2);
String packageName = cursor.getString(cursor.getColumnIndex(CryptoConsumers.PACKAGE_NAME));
String packageName = cursor.getString(cursor.getColumnIndex(ApiApps.PACKAGE_NAME));
if (packageName != null) {
text2.setText(packageName);

View File

@ -2,7 +2,7 @@ package org.sufficientlysecure.keychain.remote_api;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.KeychainContract.CryptoConsumers;
import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps;
import com.actionbarsherlock.app.SherlockListFragment;
@ -38,7 +38,7 @@ public class RegisteredAppsListFragment extends SherlockListFragment implements
// edit app settings
Intent intent = new Intent(getActivity(), AppSettingsActivity.class);
intent.setData(ContentUris.withAppendedId(
KeychainContract.CryptoConsumers.CONTENT_URI, id));
KeychainContract.ApiApps.CONTENT_URI, id));
startActivity(intent);
}
});
@ -60,20 +60,20 @@ public class RegisteredAppsListFragment extends SherlockListFragment implements
}
// These are the Contacts rows that we will retrieve.
static final String[] CONSUMERS_SUMMARY_PROJECTION = new String[] { CryptoConsumers._ID,
CryptoConsumers.PACKAGE_NAME };
static final String[] CONSUMERS_SUMMARY_PROJECTION = new String[] { ApiApps._ID,
ApiApps.PACKAGE_NAME };
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
// This is called when a new Loader needs to be created. This
// sample only has one Loader, so we don't care about the ID.
// First, pick the base URI to use depending on whether we are
// currently filtering.
Uri baseUri = CryptoConsumers.CONTENT_URI;
Uri baseUri = ApiApps.CONTENT_URI;
// Now create and return a CursorLoader that will take care of
// creating a Cursor for the data being displayed.
return new CursorLoader(getActivity(), baseUri, CONSUMERS_SUMMARY_PROJECTION, null, null,
CryptoConsumers.PACKAGE_NAME + " COLLATE LOCALIZED ASC");
ApiApps.PACKAGE_NAME + " COLLATE LOCALIZED ASC");
}
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

View File

@ -134,22 +134,26 @@ public class ServiceActivity extends SherlockFragmentActivity {
final String packageName = extras.getString(EXTRA_PACKAGE_NAME);
setContentView(R.layout.api_app_settings_activity);
LinearLayout layoutRegister = (LinearLayout) findViewById(R.id.register_crypto_consumer_register_layout);
LinearLayout layoutEdit = (LinearLayout) findViewById(R.id.register_crypto_consumer_edit_layout);
// if already registered show edit buttons
ArrayList<String> allowedPkgs = ProviderHelper.getCryptoConsumers(this);
if (allowedPkgs.contains(packageName)) {
Log.d(Constants.TAG, "Package is allowed! packageName: " + packageName);
layoutRegister.setVisibility(View.GONE);
layoutEdit.setVisibility(View.VISIBLE);
} else {
layoutRegister.setVisibility(View.VISIBLE);
layoutEdit.setVisibility(View.GONE);
}
//TODO: handle if app is already registered
// LinearLayout layoutRegister = (LinearLayout)
// findViewById(R.id.register_crypto_consumer_register_layout);
// LinearLayout layoutEdit = (LinearLayout)
// findViewById(R.id.register_crypto_consumer_edit_layout);
//
// // if already registered show edit buttons
// ArrayList<String> allowedPkgs = ProviderHelper.getCryptoConsumers(this);
// if (allowedPkgs.contains(packageName)) {
// Log.d(Constants.TAG, "Package is allowed! packageName: " + packageName);
// layoutRegister.setVisibility(View.GONE);
// layoutEdit.setVisibility(View.VISIBLE);
// } else {
// layoutRegister.setVisibility(View.VISIBLE);
// layoutEdit.setVisibility(View.GONE);
// }
Button allowButton = (Button) findViewById(R.id.register_crypto_consumer_allow);
Button disallowButton = (Button) findViewById(R.id.register_crypto_consumer_disallow);
Button allowButton = (Button) findViewById(R.id.api_register_allow);
Button disallowButton = (Button) findViewById(R.id.api_register_disallow);
allowButton.setOnClickListener(new OnClickListener() {