fix plenty of lint warnings, make some for loops into foreach, remove unused imports and throw exceptions

This commit is contained in:
uberspot 2014-03-11 23:42:45 +02:00
parent 317595dc72
commit d586ad288d
15 changed files with 24 additions and 24 deletions

View File

@ -22,7 +22,6 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import android.app.Activity; import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater; import android.view.LayoutInflater;

View File

@ -144,8 +144,8 @@ public class Preferences {
Constants.defaults.KEY_SERVERS); Constants.defaults.KEY_SERVERS);
Vector<String> servers = new Vector<String>(); Vector<String> servers = new Vector<String>();
String chunks[] = rawData.split(","); String chunks[] = rawData.split(",");
for (int i = 0; i < chunks.length; ++i) { for (String c : chunks) {
String tmp = chunks[i].trim(); String tmp = c.trim();
if (tmp.length() > 0) { if (tmp.length() > 0) {
servers.add(tmp); servers.add(tmp);
} }
@ -156,8 +156,8 @@ public class Preferences {
public void setKeyServers(String[] value) { public void setKeyServers(String[] value) {
SharedPreferences.Editor editor = mSharedPreferences.edit(); SharedPreferences.Editor editor = mSharedPreferences.edit();
String rawData = ""; String rawData = "";
for (int i = 0; i < value.length; ++i) { for (String v : value) {
String tmp = value[i].trim(); String tmp = v.trim();
if (tmp.length() == 0) { if (tmp.length() == 0) {
continue; continue;
} }

View File

@ -193,11 +193,10 @@ public class PgpHelper {
* @param context * @param context
* @param progress * @param progress
* @param file * @param file
* @throws FileNotFoundException
* @throws IOException * @throws IOException
*/ */
public static void deleteFileSecurely(Context context, ProgressDialogUpdater progress, File file) public static void deleteFileSecurely(Context context, ProgressDialogUpdater progress, File file)
throws FileNotFoundException, IOException { throws IOException {
long length = file.length(); long length = file.length();
SecureRandom random = new SecureRandom(); SecureRandom random = new SecureRandom();
RandomAccessFile raf = new RandomAccessFile(file, "rws"); RandomAccessFile raf = new RandomAccessFile(file, "rws");

View File

@ -79,8 +79,9 @@ public class PgpImportExport {
public boolean uploadKeyRingToServer(HkpKeyServer server, PGPPublicKeyRing keyring) { public boolean uploadKeyRingToServer(HkpKeyServer server, PGPPublicKeyRing keyring) {
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
ArmoredOutputStream aos = new ArmoredOutputStream(bos); ArmoredOutputStream aos = null;
try { try {
aos = new ArmoredOutputStream(bos);
aos.write(keyring.getEncoded()); aos.write(keyring.getEncoded());
aos.close(); aos.close();
@ -95,7 +96,8 @@ public class PgpImportExport {
return false; return false;
} finally { } finally {
try { try {
bos.close(); if (aos != null) aos.close();
if (bos != null) bos.close();
} catch (IOException e) { } catch (IOException e) {
} }
} }
@ -156,7 +158,7 @@ public class PgpImportExport {
} }
public Bundle exportKeyRings(ArrayList<Long> keyRingRowIds, int keyType, public Bundle exportKeyRings(ArrayList<Long> keyRingRowIds, int keyType,
OutputStream outStream) throws PgpGeneralException, FileNotFoundException, OutputStream outStream) throws PgpGeneralException,
PGPException, IOException { PGPException, IOException {
Bundle returnData = new Bundle(); Bundle returnData = new Bundle();

View File

@ -190,7 +190,7 @@ public class PgpKeyOperation {
} }
public void changeSecretKeyPassphrase(PGPSecretKeyRing keyRing, String oldPassPhrase, public void changeSecretKeyPassphrase(PGPSecretKeyRing keyRing, String oldPassPhrase,
String newPassPhrase) throws IOException, PGPException, PGPException, String newPassPhrase) throws IOException, PGPException,
NoSuchProviderException { NoSuchProviderException {
updateProgress(R.string.progress_building_key, 0, 100); updateProgress(R.string.progress_building_key, 0, 100);

View File

@ -21,6 +21,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import android.util.LongSparseArray;
import org.spongycastle.openpgp.PGPException; import org.spongycastle.openpgp.PGPException;
import org.spongycastle.openpgp.PGPPrivateKey; import org.spongycastle.openpgp.PGPPrivateKey;
import org.spongycastle.openpgp.PGPSecretKey; import org.spongycastle.openpgp.PGPSecretKey;
@ -77,7 +78,7 @@ public class PassphraseCacheService extends Service {
private BroadcastReceiver mIntentReceiver; private BroadcastReceiver mIntentReceiver;
private HashMap<Long, String> mPassphraseCache = new HashMap<Long, String>(); private LongSparseArray<String> mPassphraseCache = new LongSparseArray<String>();
Context mContext; Context mContext;
@ -347,7 +348,7 @@ public class PassphraseCacheService extends Service {
Log.d(TAG, "Timeout of keyId " + keyId + ", removed from memory!"); Log.d(TAG, "Timeout of keyId " + keyId + ", removed from memory!");
// stop whole service if no cached passphrases remaining // stop whole service if no cached passphrases remaining
if (mPassphraseCache.isEmpty()) { if (mPassphraseCache.size() == 0) {
Log.d(TAG, "No passphrases remaining in memory, stopping service!"); Log.d(TAG, "No passphrases remaining in memory, stopping service!");
stopSelf(); stopSelf();
} }

View File

@ -530,6 +530,10 @@ public class DecryptActivity extends DrawerActivity {
Log.e(Constants.TAG, "File not found!", e); Log.e(Constants.TAG, "File not found!", e);
AppMsg.makeText(this, getString(R.string.error_file_not_found, e.getMessage()), AppMsg.makeText(this, getString(R.string.error_file_not_found, e.getMessage()),
AppMsg.STYLE_ALERT).show(); AppMsg.STYLE_ALERT).show();
} finally {
try {
if (inStream != null) inStream.close();
} catch (Exception e){ }
} }
} else { } else {
inStream = new ByteArrayInputStream(mMessage.getText().toString().getBytes()); inStream = new ByteArrayInputStream(mMessage.getText().toString().getBytes());

View File

@ -81,11 +81,11 @@ public class PreferencesKeyServerActivity extends ActionBarActivity implements O
Intent intent = getIntent(); Intent intent = getIntent();
String servers[] = intent.getStringArrayExtra(EXTRA_KEY_SERVERS); String servers[] = intent.getStringArrayExtra(EXTRA_KEY_SERVERS);
if (servers != null) { if (servers != null) {
for (int i = 0; i < servers.length; ++i) { for (String serv : servers) {
KeyServerEditor view = (KeyServerEditor) mInflater.inflate( KeyServerEditor view = (KeyServerEditor) mInflater.inflate(
R.layout.key_server_editor, mEditors, false); R.layout.key_server_editor, mEditors, false);
view.setEditorListener(this); view.setEditorListener(this);
view.setValue(servers[i]); view.setValue(serv);
mEditors.addView(view); mEditors.addView(view);
} }
} }

View File

@ -199,8 +199,8 @@ public class SelectPublicKeyFragment extends ListFragmentWorkaround implements T
if (masterKeyIds != null) { if (masterKeyIds != null) {
for (int i = 0; i < getListView().getCount(); ++i) { for (int i = 0; i < getListView().getCount(); ++i) {
long keyId = mAdapter.getMasterKeyId(i); long keyId = mAdapter.getMasterKeyId(i);
for (int j = 0; j < masterKeyIds.length; ++j) { for (long masterKeyId : masterKeyIds) {
if (keyId == masterKeyIds[j]) { if (keyId == masterKeyId) {
getListView().setItemChecked(i, true); getListView().setItemChecked(i, true);
break; break;
} }

View File

@ -18,8 +18,6 @@
package org.sufficientlysecure.keychain.ui.adapter; package org.sufficientlysecure.keychain.ui.adapter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;

View File

@ -18,7 +18,6 @@
package org.sufficientlysecure.keychain.ui.adapter; package org.sufficientlysecure.keychain.ui.adapter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Set;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;

View File

@ -32,6 +32,7 @@ import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Choice; import org.sufficientlysecure.keychain.util.Choice;
import java.util.ArrayList;
import java.util.Vector; import java.util.Vector;
public class CreateKeyDialogFragment extends DialogFragment { public class CreateKeyDialogFragment extends DialogFragment {
@ -78,7 +79,7 @@ public class CreateKeyDialogFragment extends DialogFragment {
boolean wouldBeMasterKey = (childCount == 0); boolean wouldBeMasterKey = (childCount == 0);
final Spinner algorithm = (Spinner) view.findViewById(R.id.create_key_algorithm); final Spinner algorithm = (Spinner) view.findViewById(R.id.create_key_algorithm);
Vector<Choice> choices = new Vector<Choice>(); ArrayList<Choice> choices = new ArrayList<Choice>();
choices.add(new Choice(Id.choice.algorithm.dsa, getResources().getString( choices.add(new Choice(Id.choice.algorithm.dsa, getResources().getString(
R.string.dsa))); R.string.dsa)));
if (!wouldBeMasterKey) { if (!wouldBeMasterKey) {

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" > android:orientation="vertical" >

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" > android:orientation="vertical" >

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto" xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" > android:layout_height="match_parent" >