rename crypto consumers to api apps
This commit is contained in:
@@ -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);
|
||||
|
||||
// display values
|
||||
// asciiArmorCheckBox.setChecked(asciiArmor);
|
||||
try {
|
||||
asciiArmor = (cur.getInt(cur
|
||||
.getColumnIndexOrThrow(KeychainContract.ApiApps.ASCII_ARMOR)) == 1);
|
||||
|
||||
// display values
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
//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);
|
||||
// }
|
||||
|
||||
// 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() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user