use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class StateTable method fetchMeProfileChangedFlag.
/**
* Fetches the "me profile changed" flag from the database. This flag is
* used to trigger a contact sync with the server.
*
* @param readableDb Readable SQLite database for fetching the information
* @return true if the me profile has changed, false if the me profile
* hasn't changed or a database error has occurred.
*/
public static boolean fetchMeProfileChangedFlag(final SQLiteDatabase readableDb) {
boolean mValue = false;
Cursor mCursor = null;
try {
mCursor = readableDb.rawQuery("SELECT " + Field.MYCONTACTCHANGED + " FROM " + TABLE_NAME + " WHERE " + Field.STATEID + " = " + PRIMARY_STATE_KEY_VALUE, null);
if (!mCursor.moveToFirst() || mCursor.isNull(0)) {
DatabaseHelper.trace(false, "StateTable." + "fetchMeProfileChangedFlag() Return FALSE");
return false;
}
if (!mCursor.isNull(0)) {
mValue = (mCursor.getInt(0) != 0);
}
DatabaseHelper.trace(false, "StateTable." + "fetchMeProfileChangedFlag() Return[" + mValue + "]");
return mValue;
} catch (SQLiteException e) {
LogUtils.logE("StateTable.fetchMeProfileChangedFlag() " + "Exception - Unable to fetch my contact changed", e);
return false;
} finally {
CloseUtils.close(mCursor);
mCursor = null;
}
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class StateTable method fetchLogonCredentialsAndPublicKey.
/**
* Fetches cached user login credentials (with encryption information).
*
* @param details An empty LoginDetails object to be filled
* @param pubKeyDetails An empty PublicKeyDetails object to be filled
* @param readableDb Readable SQLite database for fetching the information
* @return SUCCESS or a suitable error code
*/
public static ServiceStatus fetchLogonCredentialsAndPublicKey(final LoginDetails details, final PublicKeyDetails pubKeyDetails, final SQLiteDatabase readableDb) {
if (Settings.ENABLED_DATABASE_TRACE) {
DatabaseHelper.trace(false, "StateTable.fetchLogonCredentials() " + "username[" + details.mUsername + "]");
}
Cursor cursor = null;
try {
cursor = readableDb.rawQuery("SELECT " + Field.USERNAME + "," + Field.PASSWORD + "," + Field.MOBILENO + "," + Field.SUBSCIBERID + "," + Field.REMEMBERME + "," + Field.AUTOCONNECT + "," + Field.PUBLICKEYEXPONENTIAL + "," + Field.PUBLICKEYMODULO + "," + Field.PUBLICKEYBASE64 + "," + Field.PUBLICKEYX509 + " FROM " + TABLE_NAME + " WHERE " + Field.STATEID + " = " + PRIMARY_STATE_KEY_VALUE, null);
if (!cursor.moveToFirst()) {
LogUtils.logE("StateTable.fetchLogonCredentials() Unable to " + "fetch logon credentials: State record not found");
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
details.mUsername = SqlUtils.setString(cursor, Field.USERNAME.toString());
details.mPassword = EncryptionUtils.decryptPassword(SqlUtils.setBlob(cursor, Field.PASSWORD.toString()));
details.mMobileNo = SqlUtils.setString(cursor, Field.MOBILENO.toString());
details.mSubscriberId = SqlUtils.setString(cursor, Field.SUBSCIBERID.toString());
details.mRememberMe = SqlUtils.setBoolean(cursor, Field.REMEMBERME.toString(), details.mRememberMe);
details.mAutoConnect = SqlUtils.setBoolean(cursor, Field.AUTOCONNECT.toString(), details.mAutoConnect);
/**
* Add the public key data here. *
*/
if (pubKeyDetails != null) {
// check what if it's null
pubKeyDetails.mExponential = SqlUtils.setBlob(cursor, Field.PUBLICKEYEXPONENTIAL.toString());
pubKeyDetails.mModulus = SqlUtils.setBlob(cursor, Field.PUBLICKEYMODULO.toString());
pubKeyDetails.mKeyBase64 = SqlUtils.setString(cursor, Field.PUBLICKEYBASE64.toString());
pubKeyDetails.mKeyX509 = SqlUtils.setBlob(cursor, Field.PUBLICKEYX509.toString());
}
} catch (SQLiteException e) {
LogUtils.logE("StateTable.fetchLogonCredentials() Exception - " + "Unable to fetch logon credentials", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
} finally {
CloseUtils.close(cursor);
}
return ServiceStatus.SUCCESS;
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class StateTable method modifyCredentialsAndPublicKey.
/**
* Modify cached user credentials settings (without encryption information).
*
* @param details The new credentials.
* @param pubKeyDetails The new key details.
* @param writableDb Writable SQLite database
* @return SUCCESS or a suitable error code
*/
public static ServiceStatus modifyCredentialsAndPublicKey(final LoginDetails details, final PublicKeyDetails pubKeyDetails, final SQLiteDatabase writableDb) {
if (Settings.ENABLED_DATABASE_TRACE) {
DatabaseHelper.trace(true, "StateTable." + "modifyCredentialsAndPublicKey() username[" + details.mUsername + "]");
}
ContentValues values = new ContentValues();
values.put(Field.USERNAME.toString(), details.mUsername);
if (!details.mRememberMe) {
values.put(Field.PASSWORD.toString(), (String) null);
} else {
values.put(Field.PASSWORD.toString(), EncryptionUtils.encryptPassword(details.mPassword));
}
values.put(Field.MOBILENO.toString(), details.mMobileNo);
values.put(Field.SUBSCIBERID.toString(), details.mSubscriberId);
values.put(Field.REMEMBERME.toString(), details.mRememberMe);
values.put(Field.AUTOCONNECT.toString(), details.mAutoConnect);
// add the public key data here
if (pubKeyDetails != null) {
// check what if it's null
values.put(Field.PUBLICKEYEXPONENTIAL.toString(), pubKeyDetails.mExponential);
values.put(Field.PUBLICKEYMODULO.toString(), pubKeyDetails.mModulus);
values.put(Field.PUBLICKEYBASE64.toString(), pubKeyDetails.mKeyBase64);
values.put(Field.PUBLICKEYX509.toString(), pubKeyDetails.mKeyX509);
}
try {
if (writableDb.update(TABLE_NAME, values, Field.STATEID + " = " + PRIMARY_STATE_KEY_VALUE, null) <= 0) {
LogUtils.logE("StateTable.modifyCredentialsAndPublicKey() " + "Unable to modify login credentials");
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
} catch (SQLiteException e) {
LogUtils.logE("StateTable.modifyCredentialsAndPublicKey() " + "Exception. Unable to modify credentials and public key", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
return ServiceStatus.SUCCESS;
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class StateTable method modifyCredentials.
/**
* Modify cached user credentials settings (without encryption information).
*
* @param details The new credentials.
* @param writableDb Writable SQLite database
* @return SUCCESS or a suitable error code
*/
public static ServiceStatus modifyCredentials(final LoginDetails details, final SQLiteDatabase writableDb) {
if (Settings.ENABLED_DATABASE_TRACE) {
DatabaseHelper.trace(true, "StateTable.modifyCredentials() " + "username[" + details.mUsername + "]");
}
ContentValues values = new ContentValues();
values.put(Field.USERNAME.toString(), details.mUsername);
if (!details.mRememberMe) {
values.put(Field.PASSWORD.toString(), (String) null);
} else {
values.put(Field.PASSWORD.toString(), EncryptionUtils.encryptPassword(details.mPassword));
}
values.put(Field.MOBILENO.toString(), details.mMobileNo);
values.put(Field.SUBSCIBERID.toString(), details.mSubscriberId);
values.put(Field.REMEMBERME.toString(), details.mRememberMe);
values.put(Field.AUTOCONNECT.toString(), details.mAutoConnect);
try {
if (writableDb.update(TABLE_NAME, values, Field.STATEID + " = " + PRIMARY_STATE_KEY_VALUE, null) <= 0) {
LogUtils.logE("StateTable.modifyCredentials() " + "Unable to modify login credentials");
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
} catch (SQLiteException e) {
LogUtils.logE("StateTable.modifyCredentials() Exception - " + "Unable to modify credentials", e);
return ServiceStatus.ERROR_DATABASE_CORRUPT;
}
return ServiceStatus.SUCCESS;
}
use of android.database.sqlite.SQLiteException in project 360-Engine-for-Android by 360.
the class StateTable method fetchContactRevision.
/**
* Fetches the current contact revision for the server sync.
*
* @param readableDb Readable SQLite database for fetching the information
* @return The revision number or null if an error occurs.
*/
public static Integer fetchContactRevision(final SQLiteDatabase readableDb) {
DatabaseHelper.trace(false, "StateTable.fetchContactRevision()");
Integer value = null;
Cursor c = null;
try {
c = readableDb.rawQuery("SELECT " + Field.CONTACTSREVISION + " FROM " + TABLE_NAME + " WHERE " + Field.STATEID + " = " + PRIMARY_STATE_KEY_VALUE, null);
if (!c.moveToFirst() || c.isNull(0)) {
return null;
}
value = c.getInt(0);
return value;
} catch (SQLiteException e) {
LogUtils.logE("StateTable.fetchContactRevision() Exception -" + " Unable to fetch contact revision", e);
return null;
} finally {
CloseUtils.close(c);
c = null;
}
}
Aggregations