From 5d6f57879e795e809179bffb1735c09febb8b4d1 Mon Sep 17 00:00:00 2001 From: Mohammed Ezzat Date: Sun, 13 Mar 2016 19:46:01 +0200 Subject: [PATCH] squid:S1192 - String literals should not be duplicated --- .../org/openintents/safe/CryptoHelper.java | 70 ++++++---- .../java/org/openintents/safe/DBHelper.java | 129 ++++++++++-------- 2 files changed, 110 insertions(+), 89 deletions(-) diff --git a/Safe/src/main/java/org/openintents/safe/CryptoHelper.java b/Safe/src/main/java/org/openintents/safe/CryptoHelper.java index b8d5d055..c3fda759 100644 --- a/Safe/src/main/java/org/openintents/safe/CryptoHelper.java +++ b/Safe/src/main/java/org/openintents/safe/CryptoHelper.java @@ -64,6 +64,16 @@ * @author Steven Osborn - http://steven.bitsetters.com */ public class CryptoHelper { + private static final String GENERATE_MASTER_KEY = "generateMasterKey(): "; + private static final String SET_PASSWORD = "setPassword(): "; + private static final String ENCRYPT = "encrypt(): "; + private static final String MUST_CALL_SET_PASSWORD_BEFORE_RUNNING_DECRYPT = "Must call setPassword before running decrypt."; + private static final String DECRYPT = "decrypt(): "; + private static final String ENCRYPT_WITH_SESSION_KEY = "encryptWithSessionKey(): "; + private static final String ENCRYPT_WITH_SESSION_KEY2 = "encryptWithSessionKey2(): "; + private static final String FILE_NOT_FOUND = "File not found"; + private static final String DECRYPT_INPUT_FROM = "Decrypt: Input from "; + private static final String IO_EXCEPTION = "IOException"; private static final boolean debug = false; private static String TAG = "CryptoHelper"; @@ -179,7 +189,7 @@ public static String generateMasterKey() throws NoSuchAlgorithmException { SecretKey genDesKey = keygen.generateKey(); return toHexString(genDesKey.getEncoded()); } catch (NoSuchAlgorithmException e) { - Log.e(TAG, "generateMasterKey(): " + e.toString()); + Log.e(TAG, GENERATE_MASTER_KEY + e.toString()); throw e; } } @@ -273,7 +283,7 @@ public void setPassword(String pass) { .getInstance(algorithm, "BC"); } catch (InvalidKeySpecException | NoSuchAlgorithmException | NoSuchPaddingException | NoSuchProviderException e) { - Log.e(TAG, "setPassword(): " + e.toString()); + Log.e(TAG, SET_PASSWORD + e.toString()); } // Every time we set a new password, also the session key changes: @@ -359,7 +369,7 @@ public String encrypt(String plaintext) throws CryptoHelperException { status = true; } catch (IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) { - Log.e(TAG, "encrypt(): " + e.toString()); + Log.e(TAG, ENCRYPT + e.toString()); } String stringCiphertext = toHexString(ciphertext); @@ -376,7 +386,7 @@ public String encrypt(String plaintext) throws CryptoHelperException { public String decrypt(String ciphertext) throws CryptoHelperException { status = false; // assume failure if (password == null) { - String msg = "Must call setPassword before running decrypt."; + String msg = MUST_CALL_SET_PASSWORD_BEFORE_RUNNING_DECRYPT; throw new CryptoHelperException(msg); } if (salt == null) { @@ -396,7 +406,7 @@ public String decrypt(String ciphertext) throws CryptoHelperException { status = true; } catch (IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) { - Log.e(TAG, "decrypt(): " + e.toString()); + Log.e(TAG, DECRYPT + e.toString()); } return new String(plaintext); @@ -444,7 +454,7 @@ public String encryptWithSessionKey(String plaintext) throws CryptoHelperExcepti sessionKeyEncoded = sessionKey.getEncoded(); sessionKeyString = new String(sessionKeyEncoded); } catch (NoSuchAlgorithmException e) { - Log.e(TAG, "generateMasterKey(): " + e.toString()); + Log.e(TAG, GENERATE_MASTER_KEY + e.toString()); } // Convert this to a Pbe key @@ -453,7 +463,7 @@ public String encryptWithSessionKey(String plaintext) throws CryptoHelperExcepti try { sessionPbeKey = keyFac.generateSecret(sessionPbeKeySpec); } catch (InvalidKeySpecException e) { - Log.e(TAG, "setPassword(): " + e.toString()); + Log.e(TAG, SET_PASSWORD + e.toString()); } // Encrypt the session key using the master key @@ -462,7 +472,7 @@ public String encryptWithSessionKey(String plaintext) throws CryptoHelperExcepti cipherSessionKey = pbeCipher.doFinal(sessionKeyEncoded); } catch (IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) { - Log.e(TAG, "encryptWithSessionKey(): " + e.toString()); + Log.e(TAG, ENCRYPT_WITH_SESSION_KEY + e.toString()); } // Now encrypt the text using the session key @@ -472,7 +482,7 @@ public String encryptWithSessionKey(String plaintext) throws CryptoHelperExcepti status = true; } catch (IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) { - Log.e(TAG, "encryptWithSessionKey2(): " + e.toString()); + Log.e(TAG, ENCRYPT_WITH_SESSION_KEY2 + e.toString()); } String stringCipherVersion = "A"; @@ -505,7 +515,7 @@ public String encryptWithSessionKey(String plaintext) throws CryptoHelperExcepti public String decryptWithSessionKey(String ciphertext) throws CryptoHelperException { status = false; // assume failure if (password == null) { - String msg = "Must call setPassword before running decrypt."; + String msg = MUST_CALL_SET_PASSWORD_BEFORE_RUNNING_DECRYPT; throw new CryptoHelperException(msg); } @@ -539,7 +549,7 @@ public String decryptWithSessionKey(String ciphertext) throws CryptoHelperExcept byteSessionKey = pbeCipher.doFinal(byteCipherSessionKey); status = true; } catch (IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) { - Log.e(TAG, "decrypt(): " + e.toString()); + Log.e(TAG, DECRYPT + e.toString()); } // Convert the session key into a Pbe key @@ -549,7 +559,7 @@ public String decryptWithSessionKey(String ciphertext) throws CryptoHelperExcept try { sessionPbeKey = keyFac.generateSecret(sessionPbeKeySpec); } catch (InvalidKeySpecException e) { - Log.e(TAG, "setPassword(): " + e.toString()); + Log.e(TAG, SET_PASSWORD + e.toString()); } // Use the session key to decrypt the text @@ -561,7 +571,7 @@ public String decryptWithSessionKey(String ciphertext) throws CryptoHelperExcept plaintext = pbeCipher.doFinal(byteCiphertext); status = true; } catch (IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) { - Log.e(TAG, "decrypt(): " + e.toString()); + Log.e(TAG, DECRYPT + e.toString()); } return new String(plaintext); @@ -616,7 +626,7 @@ public Uri encryptFileWithSessionKey(ContentResolver contentResolver, Uri fileUr sessionKeyEncoded = sessionKey.getEncoded(); // sessionKeyString = new String(sessionKeyEncoded); } catch (NoSuchAlgorithmException e) { - Log.e(TAG, "generateMasterKey(): " + e.toString()); + Log.e(TAG, GENERATE_MASTER_KEY + e.toString()); return null; } @@ -626,7 +636,7 @@ public Uri encryptFileWithSessionKey(ContentResolver contentResolver, Uri fileUr cipherSessionKey = pbeCipher.doFinal(sessionKeyEncoded); status = true; } catch (IllegalBlockSizeException | BadPaddingException | InvalidAlgorithmParameterException | InvalidKeyException e) { - Log.e(TAG, "encryptWithSessionKey(): " + e.toString()); + Log.e(TAG, ENCRYPT_WITH_SESSION_KEY + e.toString()); } if (!status) { return null; @@ -688,7 +698,7 @@ public Uri encryptFileWithSessionKey(ContentResolver contentResolver, Uri fileUr Log.e(TAG, "Error encrypting file", e); } } catch (FileNotFoundException e) { - Log.e(TAG, "File not found", e); + Log.e(TAG, FILE_NOT_FOUND, e); } catch (IOException e) { Log.e(TAG, "IO Exception", e); } @@ -748,7 +758,7 @@ public Uri decryptFileWithSessionKey(Context ctx, Uri fileUri) throws CryptoHelp inputPath = fileUri.getPath(); is = new java.io.FileInputStream(inputPath); if (debug) { - Log.d(TAG, "Decrypt: Input from " + inputPath); + Log.d(TAG, DECRYPT_INPUT_FROM + inputPath); } if (inputPath.endsWith(OISAFE_EXTENSION)) { outputPath = inputPath.substring(0, inputPath.length() - OISAFE_EXTENSION.length()); @@ -756,7 +766,7 @@ public Uri decryptFileWithSessionKey(Context ctx, Uri fileUri) throws CryptoHelp } else { is = contentResolver.openInputStream(fileUri); if (debug) { - Log.d(TAG, "Decrypt: Input from " + fileUri.toString()); + Log.d(TAG, DECRYPT_INPUT_FROM + fileUri.toString()); } } @@ -777,9 +787,9 @@ public Uri decryptFileWithSessionKey(Context ctx, Uri fileUri) throws CryptoHelp os.close(); } catch (FileNotFoundException e) { - Log.e(TAG, "File not found", e); + Log.e(TAG, FILE_NOT_FOUND, e); } catch (IOException e) { - Log.e(TAG, "IOException", e); + Log.e(TAG, IO_EXCEPTION, e); } catch (IllegalArgumentException e) { Log.e(TAG, "IllegalArgumentException", e); } @@ -830,12 +840,12 @@ public Uri decryptFileWithSessionKeyThroughContentProvider(Context ctx, Uri file if (fileUri.getScheme().equals("file")) { is = new java.io.FileInputStream(fileUri.getPath()); if (debug) { - Log.d(TAG, "Decrypt: Input from " + fileUri.getPath()); + Log.d(TAG, DECRYPT_INPUT_FROM + fileUri.getPath()); } } else { is = contentResolver.openInputStream(fileUri); if (debug) { - Log.d(TAG, "Decrypt: Input from " + fileUri.toString()); + Log.d(TAG, DECRYPT_INPUT_FROM + fileUri.toString()); } } FileOutputStream os = null; @@ -873,9 +883,9 @@ public Uri decryptFileWithSessionKeyThroughContentProvider(Context ctx, Uri file os.close(); } catch (FileNotFoundException e) { - Log.e(TAG, "File not found", e); + Log.e(TAG, FILE_NOT_FOUND, e); } catch (IOException e) { - Log.e(TAG, "IOException", e); + Log.e(TAG, IO_EXCEPTION, e); } if (result == false) { @@ -904,7 +914,7 @@ public boolean decryptStreamWithSessionKey(InputStream is, OutputStream os) thro } status = false; // assume failure if (password == null) { - String msg = "Must call setPassword before running decrypt."; + String msg = MUST_CALL_SET_PASSWORD_BEFORE_RUNNING_DECRYPT; throw new CryptoHelperException(msg); } @@ -966,13 +976,13 @@ public boolean decryptStreamWithSessionKey(InputStream is, OutputStream os) thro byteSessionKey = pbeCipher.doFinal(byteCipherSessionKey); status = true; } catch (IllegalBlockSizeException e) { - Log.e(TAG, "decrypt(): " + e.toString()); + Log.e(TAG, DECRYPT + e.toString()); } catch (BadPaddingException e) { - Log.e(TAG, "decrypt(): " + e.toString()); + Log.e(TAG, DECRYPT + e.toString()); } catch (InvalidKeyException e) { - Log.e(TAG, "decrypt(): " + e.toString()); + Log.e(TAG, DECRYPT + e.toString()); } catch (InvalidAlgorithmParameterException e) { - Log.e(TAG, "decrypt(): " + e.toString()); + Log.e(TAG, DECRYPT + e.toString()); } // Now decrypt the message @@ -1012,7 +1022,7 @@ public boolean decryptStreamWithSessionKey(InputStream is, OutputStream os) thro } } catch (IOException e) { - Log.e(TAG, "IOException", e); + Log.e(TAG, IO_EXCEPTION, e); } return status; diff --git a/Safe/src/main/java/org/openintents/safe/DBHelper.java b/Safe/src/main/java/org/openintents/safe/DBHelper.java index f4550a93..22f3ad1c 100644 --- a/Safe/src/main/java/org/openintents/safe/DBHelper.java +++ b/Safe/src/main/java/org/openintents/safe/DBHelper.java @@ -54,6 +54,16 @@ public class DBHelper { private static final String TABLE_SALT = "salt"; private static final String TABLE_PACKAGE_ACCESS = "package_access"; private static final String TABLE_CIPHER_ACCESS = "cipher_access"; + private static final String VERSION = "version"; + private static final String SQLITE_EXCEPTION = "SQLite exception: "; + private static final String DESCRIPTION = "description"; + private static final String WEBSITE = "website"; + private static final String USERNAME = "username"; + private static final String PASSWORD = "password"; + private static final String CATEGORY = "category"; + private static final String UNIQUE_NAME = "unique_name"; + private static final String LAST_DATE_TIME_EDIT = "lastdatetimeedit"; + private static final int DATABASE_VERSION = 4; private static String TAG = "DBHelper"; Context myCtx; @@ -65,7 +75,8 @@ public class DBHelper { private static final String PASSWORDS_CREATE = "create table " + TABLE_PASSWORDS + " (" + "id integer primary key autoincrement, " - + "category integer not null, " + + CATEGORY + + " integer not null, " + "password text not null, " + "description text not null, " + "username text, " @@ -110,7 +121,7 @@ public class DBHelper { + "dateadded text not null);"; // private static final String CIPHER_ACCESS_DROP = -// "drop table " + TABLE_CIPHER_ACCESS + ";"; +// DROP_TABLE + TABLE_CIPHER_ACCESS + ";"; private SQLiteDatabase db = null; private static boolean needsPrePopulation = false; @@ -142,7 +153,7 @@ public DBHelper(Context ctx) { } else { int version = 0; Cursor vc = db.query( - true, TABLE_DBVERSION, new String[]{"version"}, + true, TABLE_DBVERSION, new String[]{VERSION}, null, null, null, null, null, null ); if (vc.getCount() > 0) { @@ -163,7 +174,7 @@ public DBHelper(Context ctx) { Log.d(TAG, "SQLite DiskIO exception: db=" + db); } } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -179,7 +190,7 @@ private void CreateDatabase(SQLiteDatabase db) { try { db.execSQL(DBVERSION_CREATE); ContentValues args = new ContentValues(); - args.put("version", DATABASE_VERSION); + args.put(VERSION, DATABASE_VERSION); db.insert(TABLE_DBVERSION, null, args); db.execSQL(CATEGORIES_CREATE); @@ -191,7 +202,7 @@ private void CreateDatabase(SQLiteDatabase db) { db.execSQL(MASTER_KEY_CREATE); db.execSQL(SALT_CREATE); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -206,7 +217,7 @@ public void deleteDatabase() { db.execSQL(PACKAGE_ACCESS_DROP); db.execSQL(PACKAGE_ACCESS_CREATE); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -241,7 +252,7 @@ public int fetchVersion() { try { Cursor c = db.query( true, TABLE_DBVERSION, - new String[]{"version"}, + new String[]{VERSION}, null, null, null, null, null, null ); if (c.getCount() > 0) { @@ -250,7 +261,7 @@ public int fetchVersion() { } c.close(); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } return version; } @@ -278,7 +289,7 @@ public String fetchSalt() { } c.close(); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } return salt; } @@ -295,7 +306,7 @@ public void storeSalt(String salt) { args.put("salt", salt); db.insert(TABLE_SALT, null, args); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -317,7 +328,7 @@ public String fetchMasterKey() { } c.close(); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } return key; } @@ -329,7 +340,7 @@ public void storeMasterKey(String MasterKey) { args.put("encryptedkey", MasterKey); db.insert(TABLE_MASTER_KEY, null, args); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -363,7 +374,7 @@ public long addCategory(CategoryEntry entry) { try { rowID = db.insert(TABLE_CATEGORIES, null, initialValues); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } c.close(); @@ -377,7 +388,7 @@ public void deleteCategory(long Id) { try { db.delete(TABLE_CATEGORIES, "id=" + Id, null); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -407,7 +418,7 @@ public List fetchAllCategoryRows() { } c.close(); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } return ret; } @@ -435,7 +446,7 @@ public CategoryEntry fetchCategory(long Id) { } c.close(); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } return row; } @@ -444,14 +455,14 @@ public int getCategoryCount(long Id) { int count = 0; try { Cursor c = - db.rawQuery("SELECT count(*) FROM " + TABLE_PASSWORDS + " WHERE category=" + Id, null); + db.rawQuery("SELECT count(*) FROM " + TABLE_PASSWORDS + " WHERE "+ CATEGORY + "=" + Id, null); if (c.getCount() > 0) { c.moveToFirst(); count = c.getInt(0); } c.close(); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } return count; } @@ -467,7 +478,7 @@ public void updateCategory(long Id, CategoryEntry entry) { try { db.update(TABLE_CATEGORIES, args, "id=" + Id, null); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -481,7 +492,7 @@ public int countPasswords(long categoryId) { try { String selection = null; if (categoryId > 0) { - selection = "category=" + categoryId; + selection = CATEGORY + "=" + categoryId; } Cursor c = db.query( TABLE_PASSWORDS, new String[]{ @@ -492,7 +503,7 @@ public int countPasswords(long categoryId) { count = c.getInt(0); c.close(); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } //Log.i(TAG,"count="+count); return count; @@ -512,16 +523,16 @@ public List fetchAllRows(Long CategoryId) { if (CategoryId == 0) { c = db.query( TABLE_PASSWORDS, new String[]{ - "id", "password", "description", "username", "website", - "note", "category", "unique_name", "lastdatetimeedit"}, + "id", PASSWORD, DESCRIPTION, USERNAME, WEBSITE, + "note", CATEGORY, UNIQUE_NAME, LAST_DATE_TIME_EDIT}, null, null, null, null, null ); } else { c = db.query( TABLE_PASSWORDS, new String[]{ - "id", "password", "description", "username", "website", - "note", "category", "unique_name", "lastdatetimeedit"}, - "category=" + CategoryId, null, null, null, null + "id", PASSWORD, DESCRIPTION, USERNAME, WEBSITE, + "note", CATEGORY, UNIQUE_NAME, LAST_DATE_TIME_EDIT}, + CATEGORY + "=" + CategoryId, null, null, null, null ); } int numRows = c.getCount(); @@ -545,7 +556,7 @@ public List fetchAllRows(Long CategoryId) { } c.close(); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } return ret; } @@ -561,8 +572,8 @@ public PassEntry fetchPassword(long Id) { Cursor c = db.query( true, TABLE_PASSWORDS, new String[]{ - "id", "password", "description", "username", "website", - "note", "category, unique_name", "lastdatetimeedit"}, + "id", PASSWORD, DESCRIPTION, USERNAME, WEBSITE, + "note", CATEGORY + ", unique_name", LAST_DATE_TIME_EDIT}, "id=" + Id, null, null, null, null, null ); if (c.getCount() > 0) { @@ -584,7 +595,7 @@ public PassEntry fetchPassword(long Id) { } c.close(); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } return row; } @@ -597,8 +608,8 @@ public PassEntry fetchPassword(String uniqueName) { Cursor c = db.query( true, TABLE_PASSWORDS, new String[]{ - "id", "password", "description", "username", "website", - "note", "category", "unique_name", "lastdatetimeedit"}, + "id", PASSWORD, DESCRIPTION, USERNAME, WEBSITE, + "note", CATEGORY, UNIQUE_NAME, LAST_DATE_TIME_EDIT}, "unique_name='" + uniqueName + "'", null, null, null, null, null ); @@ -618,7 +629,7 @@ public PassEntry fetchPassword(String uniqueName) { } c.close(); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } return row; } @@ -641,7 +652,7 @@ public ArrayList fetchPackageAccess(long passwordID) { } } } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } finally { if (c != null) { c.close(); @@ -681,7 +692,7 @@ public HashMap> fetchPackageAccessAll() { } } } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } finally { if (c != null) { c.close(); @@ -698,7 +709,7 @@ public void addPackageAccess(long passwordID, String packageToAdd) { try { db.insert(TABLE_PACKAGE_ACCESS, null, packageAccessValues); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -709,19 +720,19 @@ public void addPackageAccess(long passwordID, String packageToAdd) { */ public long updatePassword(long Id, PassEntry entry) { ContentValues args = new ContentValues(); - args.put("description", entry.description); - args.put("username", entry.username); - args.put("password", entry.password); - args.put("website", entry.website); + args.put(DESCRIPTION, entry.description); + args.put(USERNAME, entry.username); + args.put(PASSWORD, entry.password); + args.put(WEBSITE, entry.website); args.put("note", entry.note); - args.put("unique_name", entry.uniqueName); + args.put(UNIQUE_NAME, entry.uniqueName); DateFormat dateFormatter = DateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.FULL ); Date today = new Date(); String dateOut = dateFormatter.format(today); - args.put("lastdatetimeedit", dateOut); + args.put(LAST_DATE_TIME_EDIT, dateOut); try { db.update(TABLE_PASSWORDS, args, "id=" + Id, null); } catch (SQLException e) { @@ -744,12 +755,12 @@ public void updatePasswordCategory(long Id, long newCategoryId) { } ContentValues args = new ContentValues(); - args.put("category", newCategoryId); + args.put(CATEGORY, newCategoryId); try { db.update(TABLE_PASSWORDS, args, "id=" + Id, null); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -767,25 +778,25 @@ public long addPassword(PassEntry entry) { if (entry.id != 0) { initialValues.put("id", entry.id); } - initialValues.put("category", entry.category); - initialValues.put("password", entry.password); - initialValues.put("description", entry.description); - initialValues.put("username", entry.username); - initialValues.put("website", entry.website); + initialValues.put(CATEGORY, entry.category); + initialValues.put(PASSWORD, entry.password); + initialValues.put(DESCRIPTION, entry.description); + initialValues.put(USERNAME, entry.username); + initialValues.put(WEBSITE, entry.website); initialValues.put("note", entry.note); - initialValues.put("unique_name", entry.uniqueName); + initialValues.put(UNIQUE_NAME, entry.uniqueName); DateFormat dateFormatter = DateFormat.getDateTimeInstance( DateFormat.DEFAULT, DateFormat.FULL ); Date today = new Date(); String dateOut = dateFormatter.format(today); - initialValues.put("lastdatetimeedit", dateOut); + initialValues.put(LAST_DATE_TIME_EDIT, dateOut); try { id = db.insertOrThrow(TABLE_PASSWORDS, null, initialValues); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); id = -1; } return (id); @@ -799,7 +810,7 @@ public void deletePassword(long Id) { db.delete(TABLE_PASSWORDS, "id=" + Id, null); db.delete(TABLE_PACKAGE_ACCESS, "id=" + Id, null); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -826,7 +837,7 @@ public void addCipherAccess(String packageToAdd, long expiration) { try { db.insert(TABLE_CIPHER_ACCESS, null, initialValues); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -850,7 +861,7 @@ public long fetchCipherAccess(String packageName) { } c.close(); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } return expires; } @@ -864,7 +875,7 @@ public boolean beginTransaction() { try { db.execSQL("begin transaction;"); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); return false; } return true; @@ -878,7 +889,7 @@ public void commit() { try { db.execSQL("commit;"); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } @@ -890,7 +901,7 @@ public void rollback() { try { db.execSQL("rollback;"); } catch (SQLException e) { - Log.d(TAG, "SQLite exception: " + e.getLocalizedMessage()); + Log.d(TAG, SQLITE_EXCEPTION + e.getLocalizedMessage()); } } }