Created
March 8, 2013 14:54
-
-
Save huttneab/5116962 to your computer and use it in GitHub Desktop.
gist from modified smsmmsdatabasehelper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private SecureComMmsSmsDatabaseHelper(Context context) { | |
super(context, DATABASE_NAME, null, DATABASE_VERSION); | |
mContext = context; | |
initializePassword(); | |
} | |
public void initializeWithPassword(String password){ | |
if (mPassword == null) { | |
mPassword = new char[128]; | |
} | |
Arrays.fill(mPassword, ' '); | |
if(!TextUtils.isEmpty(password)){ | |
char[] charPass = password.toCharArray(); | |
for (int i = 0; i < charPass.length; i++) { | |
mPassword[i] = charPass[i]; | |
} | |
Arrays.fill(charPass, ' '); | |
} | |
} | |
private void initializePassword(){ | |
// keyReceiver = new NewKeyReceiver(); | |
// IntentFilter filter = new IntentFilter(KeyCachingService.NEW_PASSWORD_EVENT); | |
// LocalBroadcastManager.getInstance(mContext).registerReceiver(keyReceiver, filter); | |
Intent bindInent = new Intent(mContext, KeyCachingService.class); | |
mContext.bindService(bindInent, serviceConnection, Context.BIND_AUTO_CREATE); | |
} | |
private ServiceConnection serviceConnection = new ServiceConnection(){ | |
@Override | |
public void onServiceConnected(ComponentName componentName, IBinder service) { | |
KeyCachingService keyCachingService = ((KeyCachingService.KeyCachingBinder)service).getService(); | |
String password = keyCachingService.getPassword(); | |
initializeWithPassword(password); | |
mContext.unbindService(this); | |
} | |
@Override | |
public void onServiceDisconnected(ComponentName arg0) { | |
// TODO Auto-generated method stub | |
} | |
}; | |
// private class NewKeyReceiver extends BroadcastReceiver { | |
// @Override | |
// public void onReceive(Context context, Intent intent){ | |
// initializeWithPassword(intent.getStringExtra("password")); | |
// } | |
// } | |
private String getPassword() { | |
if (!TextUtils.isEmpty(mPassword.toString())) { | |
return new String(mPassword).trim(); | |
} else { | |
return null; | |
} | |
} | |
public boolean hasPassword() { | |
return mPassword != null && mPassword[0] != ' '; | |
} | |
public boolean rekey(String oldPassword, String newPassword) { | |
if (oldPassword.equals(getPassword())) { | |
mInstance.getWritableDatabase().execSQL("PRAGMA rekey = '" + newPassword + "'"); | |
initializeWithPassword(newPassword); | |
System.gc(); | |
return true; | |
} else { | |
System.gc(); | |
return false; | |
} | |
} | |
/** | |
* Return a singleton helper for the combined MMS and SMS database. TODO | |
* remove public package | |
*/ | |
public static synchronized SecureComMmsSmsDatabaseHelper getInstance(Context context) { | |
if (mInstance == null) { | |
mInstance = new SecureComMmsSmsDatabaseHelper(context); | |
} | |
return mInstance; | |
} | |
public SQLiteDatabase getWritableDatabase() { | |
return mInstance.getWritableDatabase(getPassword()); | |
} | |
public SQLiteDatabase getReadableDatabase() { | |
return mInstance.getReadableDatabase(getPassword()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onCreate() { | |
SQLiteDatabase.loadLibs(getContext()); | |
mUseStrictPhoneNumberComparation = getContext().getResources().getBoolean(R.bool.config_use_strict_phone_number_comparation); | |
mOpenHelper = SecureComMmsSmsDatabaseHelper.getInstance(getContext()); | |
return true; | |
} | |
... | |
@Override | |
public Cursor query(Uri uri, String[] projection, | |
String selection, String[] selectionArgs, String sortOrder) { | |
SQLiteDatabase db = mOpenHelper.getReadableDatabase(); | |
Cursor cursor = null; | |
... | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment