Fix code style in keychain/service/

This commit is contained in:
uberspot 2014-03-13 19:50:45 +02:00
parent 79a8528a63
commit 540aa044e2
11 changed files with 129 additions and 87 deletions

View File

@ -49,7 +49,8 @@ import java.util.List;
* data from the activities or other apps, queues these intents, executes them, and stops itself * data from the activities or other apps, queues these intents, executes them, and stops itself
* after doing them. * after doing them.
*/ */
public class KeychainIntentService extends IntentService implements ProgressDialogUpdater, KeychainServiceListener { public class KeychainIntentService extends IntentService
implements ProgressDialogUpdater, KeychainServiceListener {
/* extras that can be given by intent */ /* extras that can be given by intent */
public static final String EXTRA_MESSENGER = "messenger"; public static final String EXTRA_MESSENGER = "messenger";
@ -307,8 +308,10 @@ public class KeychainIntentService extends IntentService implements ProgressDial
builder.enableAsciiArmorOutput(useAsciiArmor) builder.enableAsciiArmorOutput(useAsciiArmor)
.signatureForceV3(Preferences.getPreferences(this).getForceV3Signatures()) .signatureForceV3(Preferences.getPreferences(this).getForceV3Signatures())
.signatureKeyId(secretKeyId) .signatureKeyId(secretKeyId)
.signatureHashAlgorithm(Preferences.getPreferences(this).getDefaultHashAlgorithm()) .signatureHashAlgorithm(
.signaturePassphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId)); Preferences.getPreferences(this).getDefaultHashAlgorithm())
.signaturePassphrase(
PassphraseCacheService.getCachedPassphrase(this, secretKeyId));
builder.build().generateSignature(); builder.build().generateSignature();
} else if (signOnly) { } else if (signOnly) {
@ -316,21 +319,26 @@ public class KeychainIntentService extends IntentService implements ProgressDial
builder.enableAsciiArmorOutput(useAsciiArmor) builder.enableAsciiArmorOutput(useAsciiArmor)
.signatureForceV3(Preferences.getPreferences(this).getForceV3Signatures()) .signatureForceV3(Preferences.getPreferences(this).getForceV3Signatures())
.signatureKeyId(secretKeyId) .signatureKeyId(secretKeyId)
.signatureHashAlgorithm(Preferences.getPreferences(this).getDefaultHashAlgorithm()) .signatureHashAlgorithm(
.signaturePassphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId)); Preferences.getPreferences(this).getDefaultHashAlgorithm())
.signaturePassphrase(
PassphraseCacheService.getCachedPassphrase(this, secretKeyId));
builder.build().execute(); builder.build().execute();
} else { } else {
Log.d(Constants.TAG, "encrypt..."); Log.d(Constants.TAG, "encrypt...");
builder.enableAsciiArmorOutput(useAsciiArmor) builder.enableAsciiArmorOutput(useAsciiArmor)
.compressionId(compressionId) .compressionId(compressionId)
.symmetricEncryptionAlgorithm(Preferences.getPreferences(this).getDefaultEncryptionAlgorithm()) .symmetricEncryptionAlgorithm(
Preferences.getPreferences(this).getDefaultEncryptionAlgorithm())
.signatureForceV3(Preferences.getPreferences(this).getForceV3Signatures()) .signatureForceV3(Preferences.getPreferences(this).getForceV3Signatures())
.encryptionKeyIds(encryptionKeyIds) .encryptionKeyIds(encryptionKeyIds)
.encryptionPassphrase(encryptionPassphrase) .encryptionPassphrase(encryptionPassphrase)
.signatureKeyId(secretKeyId) .signatureKeyId(secretKeyId)
.signatureHashAlgorithm(Preferences.getPreferences(this).getDefaultHashAlgorithm()) .signatureHashAlgorithm(
.signaturePassphrase(PassphraseCacheService.getCachedPassphrase(this, secretKeyId)); Preferences.getPreferences(this).getDefaultHashAlgorithm())
.signaturePassphrase(
PassphraseCacheService.getCachedPassphrase(this, secretKeyId));
builder.build().execute(); builder.build().execute();
} }
@ -522,7 +530,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
ArrayList<PGPSecretKey> keys = PgpConversionHelper.BytesToPGPSecretKeyList(data ArrayList<PGPSecretKey> keys = PgpConversionHelper.BytesToPGPSecretKeyList(data
.getByteArray(SAVE_KEYRING_KEYS)); .getByteArray(SAVE_KEYRING_KEYS));
ArrayList<Integer> keysUsages = data.getIntegerArrayList(SAVE_KEYRING_KEYS_USAGES); ArrayList<Integer> keysUsages = data.getIntegerArrayList(SAVE_KEYRING_KEYS_USAGES);
ArrayList<GregorianCalendar> keysExpiryDates = (ArrayList<GregorianCalendar>) data.getSerializable(SAVE_KEYRING_KEYS_EXPIRY_DATES); ArrayList<GregorianCalendar> keysExpiryDates =
(ArrayList<GregorianCalendar>) data.getSerializable(SAVE_KEYRING_KEYS_EXPIRY_DATES);
long masterKeyId = data.getLong(SAVE_KEYRING_MASTER_KEY_ID); long masterKeyId = data.getLong(SAVE_KEYRING_MASTER_KEY_ID);
@ -577,7 +586,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
int keysTotal = 2; int keysTotal = 2;
int keysCreated = 0; int keysCreated = 0;
setProgress( setProgress(
getApplicationContext().getResources().getQuantityString(R.plurals.progress_generating, keysTotal), getApplicationContext().getResources().
getQuantityString(R.plurals.progress_generating, keysTotal),
keysCreated, keysCreated,
keysTotal); keysTotal);
PgpKeyOperation keyOperations = new PgpKeyOperation(this, this); PgpKeyOperation keyOperations = new PgpKeyOperation(this, this);
@ -746,7 +756,8 @@ public class KeychainIntentService extends IntentService implements ProgressDial
// need to have access to the bufferedInput, so we can reuse it for the possible // need to have access to the bufferedInput, so we can reuse it for the possible
// PGPObject chunks after the first one, e.g. files with several consecutive ASCII // PGPObject chunks after the first one, e.g. files with several consecutive ASCII
// armor blocks // armor blocks
BufferedInputStream bufferedInput = new BufferedInputStream(new ByteArrayInputStream(downloadedKey)); BufferedInputStream bufferedInput =
new BufferedInputStream(new ByteArrayInputStream(downloadedKey));
try { try {
// read all available blocks... (asc files can contain many blocks with BEGIN END) // read all available blocks... (asc files can contain many blocks with BEGIN END)
@ -818,9 +829,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial
private void sendErrorToHandler(Exception e) { private void sendErrorToHandler(Exception e) {
// Service was canceled. Do not send error to handler. // Service was canceled. Do not send error to handler.
if (this.mIsCanceled) if (this.mIsCanceled) {
return; return;
}
Log.e(Constants.TAG, "ApgService Exception: ", e); Log.e(Constants.TAG, "ApgService Exception: ", e);
e.printStackTrace(); e.printStackTrace();
@ -831,9 +842,9 @@ public class KeychainIntentService extends IntentService implements ProgressDial
private void sendMessageToHandler(Integer arg1, Integer arg2, Bundle data) { private void sendMessageToHandler(Integer arg1, Integer arg2, Bundle data) {
// Service was canceled. Do not send message to handler. // Service was canceled. Do not send message to handler.
if (this.mIsCanceled) if (this.mIsCanceled) {
return; return;
}
Message msg = Message.obtain(); Message msg = Message.obtain();
msg.arg1 = arg1; msg.arg1 = arg1;
if (arg2 != null) { if (arg2 != null) {

View File

@ -214,9 +214,9 @@ public class PassphraseCacheService extends Service {
} }
} }
if (!foundValidKey) if (!foundValidKey) {
return false; return false;
}
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider( PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
"SC").build("".toCharArray()); "SC").build("".toCharArray());
PGPPrivateKey testKey = secretKey.extractPrivateKey(keyDecryptor); PGPPrivateKey testKey = secretKey.extractPrivateKey(keyDecryptor);

View File

@ -22,12 +22,12 @@ import org.spongycastle.openpgp.PGPEncryptedData;
import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.Id;
public class AppSettings { public class AppSettings {
private String packageName; private String mPackageName;
private byte[] packageSignature; private byte[] mPackageSignature;
private long keyId = Id.key.none; private long mKeyId = Id.key.none;
private int encryptionAlgorithm; private int mEncryptionAlgorithm;
private int hashAlgorithm; private int mHashAlgorithm;
private int compression; private int mCompression;
public AppSettings() { public AppSettings() {
@ -35,60 +35,60 @@ public class AppSettings {
public AppSettings(String packageName, byte[] packageSignature) { public AppSettings(String packageName, byte[] packageSignature) {
super(); super();
this.packageName = packageName; this.mPackageName = packageName;
this.packageSignature = packageSignature; this.mPackageSignature = packageSignature;
// defaults: // defaults:
this.encryptionAlgorithm = PGPEncryptedData.AES_256; this.mEncryptionAlgorithm = PGPEncryptedData.AES_256;
this.hashAlgorithm = HashAlgorithmTags.SHA512; this.mHashAlgorithm = HashAlgorithmTags.SHA512;
this.compression = Id.choice.compression.zlib; this.mCompression = Id.choice.compression.zlib;
} }
public String getPackageName() { public String getPackageName() {
return packageName; return mPackageName;
} }
public void setPackageName(String packageName) { public void setPackageName(String packageName) {
this.packageName = packageName; this.mPackageName = packageName;
} }
public byte[] getPackageSignature() { public byte[] getPackageSignature() {
return packageSignature; return mPackageSignature;
} }
public void setPackageSignature(byte[] packageSignature) { public void setPackageSignature(byte[] packageSignature) {
this.packageSignature = packageSignature; this.mPackageSignature = packageSignature;
} }
public long getKeyId() { public long getKeyId() {
return keyId; return mKeyId;
} }
public void setKeyId(long scretKeyId) { public void setKeyId(long scretKeyId) {
this.keyId = scretKeyId; this.mKeyId = scretKeyId;
} }
public int getEncryptionAlgorithm() { public int getEncryptionAlgorithm() {
return encryptionAlgorithm; return mEncryptionAlgorithm;
} }
public void setEncryptionAlgorithm(int encryptionAlgorithm) { public void setEncryptionAlgorithm(int encryptionAlgorithm) {
this.encryptionAlgorithm = encryptionAlgorithm; this.mEncryptionAlgorithm = encryptionAlgorithm;
} }
public int getHashAlgorithm() { public int getHashAlgorithm() {
return hashAlgorithm; return mHashAlgorithm;
} }
public void setHashAlgorithm(int hashAlgorithm) { public void setHashAlgorithm(int hashAlgorithm) {
this.hashAlgorithm = hashAlgorithm; this.mHashAlgorithm = hashAlgorithm;
} }
public int getCompression() { public int getCompression() {
return compression; return mCompression;
} }
public void setCompression(int compression) { public void setCompression(int compression) {
this.compression = compression; this.mCompression = compression;
} }
} }

View File

@ -40,7 +40,8 @@ public class AppSettingsActivity extends ActionBarActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Inflate a "Done" custom action bar // Inflate a "Done" custom action bar
ActionBarHelper.setOneButtonView(getSupportActionBar(), R.string.api_settings_save, R.drawable.ic_action_done, ActionBarHelper.setOneButtonView(getSupportActionBar(),
R.string.api_settings_save, R.drawable.ic_action_done,
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {

View File

@ -47,7 +47,7 @@ public class AppSettingsFragment extends Fragment implements
SelectSecretKeyLayoutFragment.SelectSecretKeyCallback { SelectSecretKeyLayoutFragment.SelectSecretKeyCallback {
// model // model
private AppSettings appSettings; private AppSettings mAppSettings;
// view // view
private LinearLayout mAdvancedSettingsContainer; private LinearLayout mAdvancedSettingsContainer;
@ -62,16 +62,16 @@ public class AppSettingsFragment extends Fragment implements
private SelectSecretKeyLayoutFragment mSelectKeyFragment; private SelectSecretKeyLayoutFragment mSelectKeyFragment;
KeyValueSpinnerAdapter encryptionAdapter; KeyValueSpinnerAdapter mEncryptionAdapter;
KeyValueSpinnerAdapter hashAdapter; KeyValueSpinnerAdapter mHashAdapter;
KeyValueSpinnerAdapter compressionAdapter; KeyValueSpinnerAdapter mCompressionAdapter;
public AppSettings getAppSettings() { public AppSettings getAppSettings() {
return appSettings; return mAppSettings;
} }
public void setAppSettings(AppSettings appSettings) { public void setAppSettings(AppSettings appSettings) {
this.appSettings = appSettings; this.mAppSettings = appSettings;
setPackage(appSettings.getPackageName()); setPackage(appSettings.getPackageName());
mPackageName.setText(appSettings.getPackageName()); mPackageName.setText(appSettings.getPackageName());
@ -87,10 +87,10 @@ public class AppSettingsFragment extends Fragment implements
} }
mSelectKeyFragment.selectKey(appSettings.getKeyId()); mSelectKeyFragment.selectKey(appSettings.getKeyId());
mEncryptionAlgorithm.setSelection(encryptionAdapter.getPosition(appSettings mEncryptionAlgorithm.setSelection(mEncryptionAdapter.getPosition(appSettings
.getEncryptionAlgorithm())); .getEncryptionAlgorithm()));
mHashAlgorithm.setSelection(hashAdapter.getPosition(appSettings.getHashAlgorithm())); mHashAlgorithm.setSelection(mHashAdapter.getPosition(appSettings.getHashAlgorithm()));
mCompression.setSelection(compressionAdapter.getPosition(appSettings.getCompression())); mCompression.setSelection(mCompressionAdapter.getPosition(appSettings.getCompression()));
} }
/** /**
@ -133,14 +133,14 @@ public class AppSettingsFragment extends Fragment implements
AlgorithmNames algorithmNames = new AlgorithmNames(getActivity()); AlgorithmNames algorithmNames = new AlgorithmNames(getActivity());
encryptionAdapter = new KeyValueSpinnerAdapter(getActivity(), mEncryptionAdapter = new KeyValueSpinnerAdapter(getActivity(),
algorithmNames.getEncryptionNames()); algorithmNames.getEncryptionNames());
mEncryptionAlgorithm.setAdapter(encryptionAdapter); mEncryptionAlgorithm.setAdapter(mEncryptionAdapter);
mEncryptionAlgorithm.setOnItemSelectedListener(new OnItemSelectedListener() { mEncryptionAlgorithm.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
appSettings.setEncryptionAlgorithm((int) id); mAppSettings.setEncryptionAlgorithm((int) id);
} }
@Override @Override
@ -148,13 +148,13 @@ public class AppSettingsFragment extends Fragment implements
} }
}); });
hashAdapter = new KeyValueSpinnerAdapter(getActivity(), algorithmNames.getHashNames()); mHashAdapter = new KeyValueSpinnerAdapter(getActivity(), algorithmNames.getHashNames());
mHashAlgorithm.setAdapter(hashAdapter); mHashAlgorithm.setAdapter(mHashAdapter);
mHashAlgorithm.setOnItemSelectedListener(new OnItemSelectedListener() { mHashAlgorithm.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
appSettings.setHashAlgorithm((int) id); mAppSettings.setHashAlgorithm((int) id);
} }
@Override @Override
@ -162,14 +162,14 @@ public class AppSettingsFragment extends Fragment implements
} }
}); });
compressionAdapter = new KeyValueSpinnerAdapter(getActivity(), mCompressionAdapter = new KeyValueSpinnerAdapter(getActivity(),
algorithmNames.getCompressionNames()); algorithmNames.getCompressionNames());
mCompression.setAdapter(compressionAdapter); mCompression.setAdapter(mCompressionAdapter);
mCompression.setOnItemSelectedListener(new OnItemSelectedListener() { mCompression.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
appSettings.setCompression((int) id); mAppSettings.setCompression((int) id);
} }
@Override @Override
@ -231,7 +231,7 @@ public class AppSettingsFragment extends Fragment implements
*/ */
@Override @Override
public void onKeySelected(long secretKeyId) { public void onKeySelected(long secretKeyId) {
appSettings.setKeyId(secretKeyId); mAppSettings.setKeyId(secretKeyId);
} }
} }

View File

@ -99,7 +99,8 @@ public class OpenPgpService extends RemoteService {
intent.putExtra(RemoteServiceActivity.EXTRA_DUBLICATE_USER_IDS, dublicateUserIds); intent.putExtra(RemoteServiceActivity.EXTRA_DUBLICATE_USER_IDS, dublicateUserIds);
intent.putExtra(RemoteServiceActivity.EXTRA_DATA, data); intent.putExtra(RemoteServiceActivity.EXTRA_DATA, data);
PendingIntent pi = PendingIntent.getActivity(getBaseContext(), PRIVATE_REQUEST_CODE_USER_IDS, intent, 0); PendingIntent pi = PendingIntent.getActivity
(getBaseContext(), PRIVATE_REQUEST_CODE_USER_IDS, intent, 0);
// return PendingIntent to be executed by client // return PendingIntent to be executed by client
Intent result = new Intent(); Intent result = new Intent();
@ -125,7 +126,8 @@ public class OpenPgpService extends RemoteService {
intent.putExtra(RemoteServiceActivity.EXTRA_SECRET_KEY_ID, keyId); intent.putExtra(RemoteServiceActivity.EXTRA_SECRET_KEY_ID, keyId);
// pass params through to activity that it can be returned again later to repeat pgp operation // pass params through to activity that it can be returned again later to repeat pgp operation
intent.putExtra(RemoteServiceActivity.EXTRA_DATA, data); intent.putExtra(RemoteServiceActivity.EXTRA_DATA, data);
PendingIntent pi = PendingIntent.getActivity(getBaseContext(), PRIVATE_REQUEST_CODE_PASSPHRASE, intent, 0); PendingIntent pi = PendingIntent.getActivity
(getBaseContext(), PRIVATE_REQUEST_CODE_PASSPHRASE, intent, 0);
// return PendingIntent to be executed by client // return PendingIntent to be executed by client
Intent result = new Intent(); Intent result = new Intent();
@ -207,7 +209,8 @@ public class OpenPgpService extends RemoteService {
} else { } else {
Intent result = new Intent(); Intent result = new Intent();
result.putExtra(OpenPgpApi.RESULT_ERROR, result.putExtra(OpenPgpApi.RESULT_ERROR,
new OpenPgpError(OpenPgpError.GENERIC_ERROR, "Missing parameter user_ids or key_ids!")); new OpenPgpError(OpenPgpError.GENERIC_ERROR,
"Missing parameter user_ids or key_ids!"));
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR); result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
return result; return result;
} }
@ -288,7 +291,8 @@ public class OpenPgpService extends RemoteService {
PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder(this, inputData, os); PgpDecryptVerify.Builder builder = new PgpDecryptVerify.Builder(this, inputData, os);
builder.assumeSymmetric(false) // no support for symmetric encryption builder.assumeSymmetric(false) // no support for symmetric encryption
.enforcedKeyId(appSettings.getKeyId()) // allow only the private key for this app for decryption // allow only the private key for this app for decryption
.enforcedKeyId(appSettings.getKeyId())
.passphrase(passphrase); .passphrase(passphrase);
// TODO: currently does not support binary signed-only content // TODO: currently does not support binary signed-only content
@ -402,7 +406,8 @@ public class OpenPgpService extends RemoteService {
// version code is required and needs to correspond to version code of service! // version code is required and needs to correspond to version code of service!
if (data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) != OpenPgpApi.API_VERSION) { if (data.getIntExtra(OpenPgpApi.EXTRA_API_VERSION, -1) != OpenPgpApi.API_VERSION) {
Intent result = new Intent(); Intent result = new Intent();
OpenPgpError error = new OpenPgpError(OpenPgpError.INCOMPATIBLE_API_VERSIONS, "Incompatible API versions!"); OpenPgpError error = new OpenPgpError
(OpenPgpError.INCOMPATIBLE_API_VERSIONS, "Incompatible API versions!");
result.putExtra(OpenPgpApi.RESULT_ERROR, error); result.putExtra(OpenPgpApi.RESULT_ERROR, error);
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR); result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
return result; return result;

View File

@ -34,13 +34,13 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.ApiApps;
public class RegisteredAppsAdapter extends CursorAdapter { public class RegisteredAppsAdapter extends CursorAdapter {
private LayoutInflater mInflater; private LayoutInflater mInflater;
private PackageManager pm; private PackageManager mPM;
public RegisteredAppsAdapter(Context context, Cursor c, int flags) { public RegisteredAppsAdapter(Context context, Cursor c, int flags) {
super(context, c, flags); super(context, c, flags);
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
pm = context.getApplicationContext().getPackageManager(); mPM = context.getApplicationContext().getPackageManager();
} }
@Override @Override
@ -52,10 +52,10 @@ public class RegisteredAppsAdapter extends CursorAdapter {
if (packageName != null) { if (packageName != null) {
// get application name // get application name
try { try {
ApplicationInfo ai = pm.getApplicationInfo(packageName, 0); ApplicationInfo ai = mPM.getApplicationInfo(packageName, 0);
text.setText(pm.getApplicationLabel(ai)); text.setText(mPM.getApplicationLabel(ai));
icon.setImageDrawable(pm.getApplicationIcon(ai)); icon.setImageDrawable(mPM.getApplicationIcon(ai));
} catch (final NameNotFoundException e) { } catch (final NameNotFoundException e) {
// fallback // fallback
text.setText(packageName); text.setText(packageName);

View File

@ -98,4 +98,4 @@ public class RegisteredAppsListFragment extends ListFragment implements
mAdapter.swapCursor(null); mAdapter.swapCursor(null);
} }
} }

View File

@ -83,7 +83,8 @@ public abstract class RemoteService extends Service {
intent.putExtra(RemoteServiceActivity.EXTRA_PACKAGE_SIGNATURE, packageSignature); intent.putExtra(RemoteServiceActivity.EXTRA_PACKAGE_SIGNATURE, packageSignature);
intent.putExtra(RemoteServiceActivity.EXTRA_DATA, data); intent.putExtra(RemoteServiceActivity.EXTRA_DATA, data);
PendingIntent pi = PendingIntent.getActivity(getBaseContext(), PRIVATE_REQUEST_CODE_REGISTER, intent, 0); PendingIntent pi = PendingIntent.getActivity(getBaseContext(),
PRIVATE_REQUEST_CODE_REGISTER, intent, 0);
// return PendingIntent to be executed by client // return PendingIntent to be executed by client
Intent result = new Intent(); Intent result = new Intent();
@ -97,10 +98,12 @@ public abstract class RemoteService extends Service {
Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class); Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class);
intent.setAction(RemoteServiceActivity.ACTION_ERROR_MESSAGE); intent.setAction(RemoteServiceActivity.ACTION_ERROR_MESSAGE);
intent.putExtra(RemoteServiceActivity.EXTRA_ERROR_MESSAGE, getString(R.string.api_error_wrong_signature)); intent.putExtra(RemoteServiceActivity.EXTRA_ERROR_MESSAGE,
getString(R.string.api_error_wrong_signature));
intent.putExtra(RemoteServiceActivity.EXTRA_DATA, data); intent.putExtra(RemoteServiceActivity.EXTRA_DATA, data);
PendingIntent pi = PendingIntent.getActivity(getBaseContext(), PRIVATE_REQUEST_CODE_ERROR, intent, 0); PendingIntent pi = PendingIntent.getActivity(getBaseContext(),
PRIVATE_REQUEST_CODE_ERROR, intent, 0);
// return PendingIntent to be executed by client // return PendingIntent to be executed by client
Intent result = new Intent(); Intent result = new Intent();
@ -137,8 +140,9 @@ public abstract class RemoteService extends Service {
AppSettings settings = ProviderHelper.getApiAppSettings(this, uri); AppSettings settings = ProviderHelper.getApiAppSettings(this, uri);
if (settings != null) if (settings != null) {
return settings; return settings;
}
} }
return null; return null;
@ -212,7 +216,7 @@ public abstract class RemoteService extends Service {
return true; return true;
} else { } else {
throw new WrongPackageSignatureException( throw new WrongPackageSignatureException(
"PACKAGE NOT ALLOWED! Signature wrong! (Signature not equals signature from database)"); "PACKAGE NOT ALLOWED! Signature wrong! (Signature not equals signature from database)");
} }
} }

View File

@ -87,7 +87,8 @@ public class RemoteServiceActivity extends ActionBarActivity {
final byte[] packageSignature = extras.getByteArray(EXTRA_PACKAGE_SIGNATURE); final byte[] packageSignature = extras.getByteArray(EXTRA_PACKAGE_SIGNATURE);
// Inflate a "Done"/"Cancel" custom action bar view // Inflate a "Done"/"Cancel" custom action bar view
ActionBarHelper.setTwoButtonView(getSupportActionBar(), R.string.api_register_allow, R.drawable.ic_action_done, ActionBarHelper.setTwoButtonView(getSupportActionBar(),
R.string.api_register_allow, R.drawable.ic_action_done,
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -107,13 +108,14 @@ public class RemoteServiceActivity extends ActionBarActivity {
RemoteServiceActivity.this.finish(); RemoteServiceActivity.this.finish();
} }
} }
}, R.string.api_register_disallow, R.drawable.ic_action_cancel, new View.OnClickListener() { }, R.string.api_register_disallow, R.drawable.ic_action_cancel,
@Override new View.OnClickListener() {
public void onClick(View v) { @Override
// Disallow public void onClick(View v) {
RemoteServiceActivity.this.setResult(RESULT_CANCELED); // Disallow
RemoteServiceActivity.this.finish(); RemoteServiceActivity.this.setResult(RESULT_CANCELED);
} RemoteServiceActivity.this.finish();
}
} }
); );
@ -160,7 +162,8 @@ public class RemoteServiceActivity extends ActionBarActivity {
} }
// Inflate a "Done"/"Cancel" custom action bar view // Inflate a "Done"/"Cancel" custom action bar view
ActionBarHelper.setTwoButtonView(getSupportActionBar(), R.string.btn_okay, R.drawable.ic_action_done, ActionBarHelper.setTwoButtonView(getSupportActionBar(),
R.string.btn_okay, R.drawable.ic_action_done,
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -213,7 +216,8 @@ public class RemoteServiceActivity extends ActionBarActivity {
String text = "<font color=\"red\">" + errorMessage + "</font>"; String text = "<font color=\"red\">" + errorMessage + "</font>";
// Inflate a "Done" custom action bar view // Inflate a "Done" custom action bar view
ActionBarHelper.setOneButtonView(getSupportActionBar(), R.string.btn_okay, R.drawable.ic_action_done, ActionBarHelper.setOneButtonView(getSupportActionBar(),
R.string.btn_okay, R.drawable.ic_action_done,
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override

View File

@ -1,3 +1,20 @@
/*
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.service.remote; package org.sufficientlysecure.keychain.service.remote;
public class WrongPackageSignatureException extends Exception { public class WrongPackageSignatureException extends Exception {
@ -7,4 +24,4 @@ public class WrongPackageSignatureException extends Exception {
public WrongPackageSignatureException(String message) { public WrongPackageSignatureException(String message) {
super(message); super(message);
} }
} }