Original code:
package com.example.sqlcipher_exemplo;
import java.io.File;
import net.sqlcipher.Cursor;
import net.sqlcipher.database.SQLiteDatabase;
import net.sqlcipher.database.SQLiteDatabaseHook;
import android.app.Activity;
import android.content.ContentValues;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends Activity
{
EventDataSQLHelper eventsData;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if ("google_sdk".equals( Build.PRODUCT ) || Build.FINGERPRINT.startsWith("generic"))
{
Log.i("EMULADOR", "rodando no emulador");
}
else
{
Log.i("DISPOSITIVO", "rodando no dispositivo");
}
SQLiteDatabase.loadLibs(this);
String password = "123";
eventsData = new EventDataSQLHelper(this);
SQLiteDatabase db = eventsData.getWritableDatabase(password);
for(int i=1; i<100; i++)
{
addEvent("Hello Android Event "+i, db);
}
db.close();
db = eventsData.getReadableDatabase(password);
Cursor cursor = getEvents(db);
showEvents(cursor);
db.close();
}
private void addEvent (String title, SQLiteDatabase db)
{
ContentValues values = new ContentValues();
values.put(EventDataSQLHelper.TIME, System.currentTimeMillis());
values.put(EventDataSQLHelper.TITLE, title);
db.insert(EventDataSQLHelper.TABLE, null, values);
}
private Cursor getEvents(SQLiteDatabase db)
{
Cursor cursor = db.query(EventDataSQLHelper.TABLE, null, null, null, null, null, null);
startManagingCursor(cursor);
return cursor;
}
private void showEvents(Cursor cursor)
{
StringBuilder ret = new StringBuilder("Saved Events:\n\n");
while (cursor.moveToNext())
{
long id = cursor.getLong(0);
long time = cursor.getLong(1);
String title = cursor.getString(2);
ret.append(id+": "+time+":"+title+"\n");
}
Log.i("sqldemo", ret.toString());
}
/*
private void decryptDatabase()
{
File unencryptedFile = getDatabasePath("events.db");
unencryptedFile.delete();
File databaseFile = getDatabasePath("events.db");
SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {
public void preKey(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase
.rawExecSQL("PRAGMA cipher_default_use_hmac = off;");
}
public void postKey(SQLiteDatabase sqLiteDatabase)
{
}
};
SQLiteDatabase database = SQLiteDatabase.openOrCreateDatabase(
databaseFile, "123", null, hook); // Exception
if (database.isOpen())
{
database.rawExecSQL(String.format(
"ATTACH DATABASE '%s' as plaintext KEY '';",
unencryptedFile.getAbsolutePath()));
database.rawExecSQL("SELECT sqlcipher_export('plaintext');");
database.rawExecSQL("DETACH DATABASE plaintext;");
android.database.sqlite.SQLiteDatabase sqlDB = android.database.sqlite.SQLiteDatabase
.openOrCreateDatabase(unencryptedFile, null);
sqlDB.close();
database.close();
}
databaseFile.delete();
}*/
}
Code after Proguard:
package com.example.sqlcipher_exemplo;
import android.app.Activity;
import android.content.ContentValues;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import net.sqlcipher.Cursor;
import net.sqlcipher.database.SQLiteDatabase;
public class MainActivity
extends Activity
{
a a;
private Cursor a(SQLiteDatabase paramSQLiteDatabase)
{
paramSQLiteDatabase = paramSQLiteDatabase.query("events", null, null, null, null, null, null);
startManagingCursor(paramSQLiteDatabase);
return paramSQLiteDatabase;
}
private void a(String paramString, SQLiteDatabase paramSQLiteDatabase)
{
ContentValues localContentValues = new ContentValues();
localContentValues.put("time", Long.valueOf(System.currentTimeMillis()));
localContentValues.put("title", paramString);
paramSQLiteDatabase.insert("events", null, localContentValues);
}
private void a(Cursor paramCursor)
{
StringBuilder localStringBuilder = new StringBuilder("Saved Events:\n\n");
for (;;)
{
if (!paramCursor.moveToNext())
{
Log.i("sqldemo", localStringBuilder.toString());
return;
}
long l1 = paramCursor.getLong(0);
long l2 = paramCursor.getLong(1);
String str = paramCursor.getString(2);
localStringBuilder.append(l1 + ": " + l2 + ":" + str + "\n");
}
}
protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
setContentView(2130903040);
int i;
if (("google_sdk".equals(Build.PRODUCT)) || (Build.FINGERPRINT.startsWith("generic")))
{
Log.i("EMULADOR", "rodando no emulador");
SQLiteDatabase.loadLibs(this);
this.a = new a(this);
paramBundle = this.a.getWritableDatabase("123");
i = 1;
}
for (;;)
{
if (i >= 100)
{
paramBundle.close();
paramBundle = this.a.getReadableDatabase("123");
a(a(paramBundle));
paramBundle.close();
return;
Log.i("DISPOSITIVO", "rodando no dispositivo");
break;
}
a("Hello Android Event " + i, paramBundle);
i += 1;
}
}
}