App settings activity

This commit is contained in:
Dominik Schürmann 2013-09-04 23:47:40 +02:00
parent d8bd6e2946
commit fcec7e830c
13 changed files with 174 additions and 50 deletions

View File

@ -3,7 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:orientation="vertical"
android:padding="8dp" >
<fragment
android:id="@+id/api_app_settings_fragment"
@ -23,11 +24,10 @@
android:id="@+id/register_crypto_consumer_question"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Package TODO requests permanent access to OpenPGP Keychain\&apos;s API. Allow permanent access?"
android:text="TODO: use string"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:id="@+id/register_crypto_consumer_register_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
@ -38,16 +38,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Disallow access" />
android:text="@string/api_register_disallow" />
<Button
android:id="@+id/register_crypto_consumer_allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Allow access" />
android:text="@string/api_register_allow" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:padding="8dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
@ -24,14 +25,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Revoke access" />
android:text="@string/api_settings_revoke" />
<Button
android:id="@+id/register_crypto_consumer_allow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Save" />
android:text="@string/api_settings_save" />
</LinearLayout>
</LinearLayout>

View File

@ -11,36 +11,37 @@
android:paddingBottom="3dip" >
<TextView
android:id="@+id/register_crypto_consumer_select_key"
android:id="@+id/api_app_settings_selected_key"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:text="Select key"
android:text="@string/api_settings_no_key"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/register_crypto_consumer_select_key_button"
android:id="@+id/api_app_settings_select_key_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="TD Select priv key" />
android:text="@string/api_settings_select_key" />
</LinearLayout>
<Button
android:id="@+id/api_app_settings_advanced_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="show advanced settings" />
android:text="@string/api_settings_show_advanced" />
<LinearLayout
android:id="@+id/api_app_settings_advanced"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:orientation="horizontal"
android:visibility="invisible" >
<CheckBox
android:id="@+id/asciiArmour"
android:id="@+id/api_app_ascii_armor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"

View File

@ -359,9 +359,18 @@
<string name="intent_import_key">OpenPGP: Import Keyring</string>
<string name="intent_send_encrypt">OpenPGP: Encrypt</string>
<string name="intent_send_decrypt">OpenPGP: Decrypt</string>
<!-- Remote API -->
<string name="api_no_apps">No registered applications!</string>
<string name="api_unknown_app">Unknown app</string>
<string name="api_settings_show_advanced">Show advanced settings…</string>
<string name="api_settings_hide_advanced">Hide advanced settings…</string>
<string name="api_settings_no_key">No key selected</string>
<string name="api_settings_select_key">Select key</string>
<string name="api_settings_save">Save</string>
<string name="api_settings_revoke">Revoke access</string>
<string name="api_register_text">%1$s (%2$s) requests access to OpenPGP Keychain\'s API.\n\nAllow permanent access?</string>
<string name="api_register_allow">Allow access</string>
<string name="api_register_disallow">Disallow access</string>
</resources>

View File

@ -611,6 +611,13 @@ public class KeychainProvider extends ContentProvider {
case CRYPTO_CONSUMERS:
qb.setTables(Tables.CRYPTO_CONSUMERS);
break;
case CRYPTO_CONSUMERS_BY_ROW_ID:
qb.setTables(Tables.CRYPTO_CONSUMERS);
qb.appendWhere(BaseColumns._ID + " = ");
qb.appendWhereEscapeString(uri.getLastPathSegment());
break;
case CRYPTO_CONSUMERS_BY_PACKAGE_NAME:
qb.setTables(Tables.CRYPTO_CONSUMERS);

View File

@ -2,34 +2,89 @@ package org.sufficientlysecure.keychain.remote_api;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.util.Log;
import android.content.ContentUris;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockFragmentActivity;
public class AppSettingsActivity extends SherlockFragmentActivity {
private PackageManager pm;
long id;
String packageName;
long keyId;
boolean asciiArmor;
// derived
String appName;
// view
TextView selectedKey;
Button selectKeyButton;
CheckBox asciiArmorCheckBox;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pm = getApplicationContext().getPackageManager();
setContentView(R.layout.api_app_settings_activity);
// check if add new or edit existing
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);
Intent intent = getIntent();
Uri appUri = intent.getData();
if (appUri == null) {
Log.e(Constants.TAG, "Intent data missing. Should be Uri of app!");
finish();
return;
} else {
Log.d(Constants.TAG, "uri: " + appUri);
loadData(appUri);
}
}
private void loadData(Uri appUri) {
Cursor cur = getContentResolver().query(appUri, null, null, null, null);
id = ContentUris.parseId(appUri);
if (cur.moveToFirst()) {
do {
packageName = cur.getString(cur
.getColumnIndex(KeychainContract.CryptoConsumers.PACKAGE_NAME));
// get application name
try {
ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
appName = (String) pm.getApplicationLabel(ai);
} catch (final NameNotFoundException e) {
appName = getString(R.string.api_unknown_app);
}
// asciiArmor = (cur.getInt(cur
// .getColumnIndex(KeychainContract.CryptoConsumers.ASCII_ARMOR)) == 1);
// display values
// asciiArmorCheckBox.setChecked(asciiArmor);
} while (cur.moveToNext());
}
Log.d(Constants.TAG, "uri: " + appUri);
}
}

View File

@ -1,15 +1,28 @@
package org.sufficientlysecure.keychain.remote_api;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.SelectSecretKeyActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.LinearLayout;
public class AppSettingsFragment extends Fragment {
private LinearLayout advancedSettingsContainer;
private Button advancedSettingsButton;
private Button selectKeyButton;
/**
* Inflate the layout for this fragment
*/
@ -17,4 +30,55 @@ public class AppSettingsFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.api_app_settings_fragment, container, false);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
advancedSettingsButton = (Button) getActivity().findViewById(
R.id.api_app_settings_advanced_button);
advancedSettingsContainer = (LinearLayout) getActivity().findViewById(
R.id.api_app_settings_advanced);
selectKeyButton = (Button) getActivity().findViewById(
R.id.api_app_settings_select_key_button);
final Animation visibleAnimation = new AlphaAnimation(0.0f, 1.0f);
visibleAnimation.setDuration(250);
final Animation invisibleAnimation = new AlphaAnimation(1.0f, 0.0f);
invisibleAnimation.setDuration(250);
// TODO: Better: collapse/expand animation
// final Animation animation2 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
// Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f,
// Animation.RELATIVE_TO_SELF, 0.0f);
// animation2.setDuration(150);
advancedSettingsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (advancedSettingsContainer.getVisibility() == View.VISIBLE) {
advancedSettingsContainer.startAnimation(invisibleAnimation);
advancedSettingsContainer.setVisibility(View.INVISIBLE);
} else {
advancedSettingsContainer.startAnimation(visibleAnimation);
advancedSettingsContainer.setVisibility(View.VISIBLE);
}
}
});
selectKeyButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
selectSecretKey();
}
});
}
private void selectSecretKey() {
Intent intent = new Intent(getActivity(), SelectSecretKeyActivity.class);
startActivityForResult(intent, Id.request.secret_keys);
}
}

View File

@ -35,9 +35,8 @@ public class RegisteredAppsAdapter extends CursorAdapter {
private LayoutInflater mInflater;
private PackageManager pm;
@SuppressWarnings("deprecation")
public RegisteredAppsAdapter(Context context, Cursor c) {
super(context, c);
public RegisteredAppsAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
mInflater = LayoutInflater.from(context);
pm = context.getApplicationContext().getPackageManager();

View File

@ -51,7 +51,7 @@ public class RegisteredAppsListFragment extends SherlockListFragment implements
setHasOptionsMenu(true);
// Create an empty adapter we will use to display the loaded data.
mAdapter = new RegisteredAppsAdapter(getActivity(), null);
mAdapter = new RegisteredAppsAdapter(getActivity(), null, 0);
setListAdapter(mAdapter);
// Prepare the loader. Either re-connect with an existing one,

View File

@ -67,7 +67,7 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements
// application this would come from a resource.
setEmptyText(getString(R.string.listEmpty));
mAdapter = new SelectKeyCursorAdapter(mActivity, mListView, null, Id.type.public_key);
mAdapter = new SelectKeyCursorAdapter(mActivity, null, 0, mListView, Id.type.public_key);
setListAdapter(mAdapter);
@ -160,11 +160,12 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements
+ SelectKeyCursorAdapter.PROJECTION_ROW_AVAILABLE,
"(SELECT COUNT(valid_keys." + Keys._ID + ") FROM " + Tables.KEYS
+ " AS valid_keys WHERE valid_keys." + Keys.KEY_RING_ROW_ID + " = "
+ KeychainDatabase.Tables.KEY_RINGS + "." + KeyRings._ID + " AND valid_keys."
+ Keys.IS_REVOKED + " = '0' AND valid_keys." + Keys.CAN_ENCRYPT
+ " = '1' AND valid_keys." + Keys.CREATION + " <= '" + now + "' AND "
+ "(valid_keys." + Keys.EXPIRY + " IS NULL OR valid_keys." + Keys.EXPIRY
+ " >= '" + now + "')) AS " + SelectKeyCursorAdapter.PROJECTION_ROW_VALID, };
+ KeychainDatabase.Tables.KEY_RINGS + "." + KeyRings._ID
+ " AND valid_keys." + Keys.IS_REVOKED + " = '0' AND valid_keys."
+ Keys.CAN_ENCRYPT + " = '1' AND valid_keys." + Keys.CREATION + " <= '"
+ now + "' AND " + "(valid_keys." + Keys.EXPIRY + " IS NULL OR valid_keys."
+ Keys.EXPIRY + " >= '" + now + "')) AS "
+ SelectKeyCursorAdapter.PROJECTION_ROW_VALID, };
String inMasterKeyList = null;
if (mSelectedMasterKeyIds != null && mSelectedMasterKeyIds.length > 0) {

View File

@ -73,7 +73,7 @@ public class SelectSecretKeyFragment extends SherlockListFragment implements
// application this would come from a resource.
setEmptyText(getString(R.string.listEmpty));
mAdapter = new SelectKeyCursorAdapter(mActivity, mListView, null, Id.type.secret_key);
mAdapter = new SelectKeyCursorAdapter(mActivity, null, 0, mListView, Id.type.secret_key);
setListAdapter(mAdapter);

View File

@ -23,19 +23,14 @@ import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.spongycastle.openpgp.PGPKeyRing;
import org.spongycastle.openpgp.PGPObjectFactory;
import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.spongycastle.openpgp.PGPPublicKeyRingCollection;
import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.spongycastle.openpgp.PGPSecretKeyRingCollection;
import org.spongycastle.openpgp.PGPUtil;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.helper.PgpConversionHelper;
import org.sufficientlysecure.keychain.helper.PgpHelper;
import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log;
@ -45,11 +40,6 @@ import org.sufficientlysecure.keychain.R;
import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;
/**
* A custom Loader to search for bad adware apps, based on
* https://github.com/brosmike/AirPush-Detector. Daniel Bjorge licensed it under Apachev2 after
* asking him by mail.
*/
public class ImportKeysListLoader extends AsyncTaskLoader<List<Map<String, String>>> {
public static final String MAP_ATTR_USER_ID = "user_id";
public static final String MAP_ATTR_FINGERPINT = "fingerprint";

View File

@ -44,9 +44,9 @@ public class SelectKeyCursorAdapter extends CursorAdapter {
public final static String PROJECTION_ROW_AVAILABLE = "available";
public final static String PROJECTION_ROW_VALID = "valid";
@SuppressWarnings("deprecation")
public SelectKeyCursorAdapter(Context context, ListView listView, Cursor c, int keyType) {
super(context, c);
public SelectKeyCursorAdapter(Context context, Cursor c, int flags, ListView listView,
int keyType) {
super(context, c, flags);
mInflater = LayoutInflater.from(context);
mListView = listView;
@ -65,8 +65,7 @@ public class SelectKeyCursorAdapter extends CursorAdapter {
@Override
public void bindView(View view, Context context, Cursor cursor) {
boolean valid = cursor.getInt(cursor
.getColumnIndex(PROJECTION_ROW_VALID)) > 0;
boolean valid = cursor.getInt(cursor.getColumnIndex(PROJECTION_ROW_VALID)) > 0;
TextView mainUserId = (TextView) view.findViewById(R.id.mainUserId);
mainUserId.setText(R.string.unknownUserId);
@ -101,8 +100,7 @@ public class SelectKeyCursorAdapter extends CursorAdapter {
status.setText(R.string.canSign);
}
} else {
if (cursor.getInt(cursor
.getColumnIndex(PROJECTION_ROW_AVAILABLE)) > 0) {
if (cursor.getInt(cursor.getColumnIndex(PROJECTION_ROW_AVAILABLE)) > 0) {
// has some CAN_ENCRYPT keys, but col(ROW_VALID) = 0, so must be revoked or
// expired
status.setText(R.string.expired);