Panagiotis Triantafyllou

new sdk version, migration db to the new sqlcipher lib

1 #Fri Jul 26 17:08:44 EEST 2024 1 #Fri Jul 26 17:08:44 EEST 2024
2 distributionBase=GRADLE_USER_HOME 2 distributionBase=GRADLE_USER_HOME
3 distributionPath=wrapper/dists 3 distributionPath=wrapper/dists
4 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip 4 +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
5 zipStoreBase=GRADLE_USER_HOME 5 zipStoreBase=GRADLE_USER_HOME
6 zipStorePath=wrapper/dists 6 zipStorePath=wrapper/dists
......
...@@ -5,7 +5,7 @@ android.buildFeatures.buildConfig = true ...@@ -5,7 +5,7 @@ android.buildFeatures.buildConfig = true
5 5
6 ext { 6 ext {
7 PUBLISH_GROUP_ID = 'ly.warp' 7 PUBLISH_GROUP_ID = 'ly.warp'
8 - PUBLISH_VERSION = '4.5.5.4m7' 8 + PUBLISH_VERSION = '4.5.5.4m8'
9 PUBLISH_ARTIFACT_ID = 'warply-android-sdk' 9 PUBLISH_ARTIFACT_ID = 'warply-android-sdk'
10 } 10 }
11 11
...@@ -97,9 +97,9 @@ dependencies { ...@@ -97,9 +97,9 @@ dependencies {
97 implementation 'com.huawei.hms:ads-identifier:3.4.56.300' 97 implementation 'com.huawei.hms:ads-identifier:3.4.56.300'
98 98
99 //------------------------------ SQLCipher -----------------------------// 99 //------------------------------ SQLCipher -----------------------------//
100 - api "net.zetetic:android-database-sqlcipher:4.5.2" 100 + api "net.zetetic:sqlcipher-android:4.13.0"
101 api "androidx.sqlite:sqlite:2.2.0" 101 api "androidx.sqlite:sqlite:2.2.0"
102 - api 'com.getkeepsafe.relinker:relinker:1.4.4' 102 + api 'com.getkeepsafe.relinker:relinker:1.4.5'
103 103
104 //------------------------------ Retrofit -----------------------------// 104 //------------------------------ Retrofit -----------------------------//
105 implementation 'com.squareup.retrofit2:retrofit:2.9.0' 105 implementation 'com.squareup.retrofit2:retrofit:2.9.0'
......
...@@ -13,10 +13,9 @@ import androidx.annotation.Nullable; ...@@ -13,10 +13,9 @@ import androidx.annotation.Nullable;
13 13
14 import com.getkeepsafe.relinker.ReLinker; 14 import com.getkeepsafe.relinker.ReLinker;
15 15
16 -import net.sqlcipher.DatabaseUtils; 16 +import net.zetetic.database.sqlcipher.SQLiteDatabase;
17 -import net.sqlcipher.database.SQLiteDatabase; 17 +import net.zetetic.database.sqlcipher.SQLiteOpenHelper;
18 -import net.sqlcipher.database.SQLiteOpenHelper; 18 +import net.zetetic.database.sqlcipher.SQLiteStatement;
19 -import net.sqlcipher.database.SQLiteStatement;
20 19
21 import org.json.JSONArray; 20 import org.json.JSONArray;
22 import org.json.JSONObject; 21 import org.json.JSONObject;
...@@ -45,7 +44,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -45,7 +44,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
45 } 44 }
46 45
47 private static final String DB_NAME = "warply.db"; 46 private static final String DB_NAME = "warply.db";
48 - private static final int DB_VERSION = 14; 47 + private static final int DB_VERSION = 15;
49 private static final String KEY_CIPHER = "tn#mpOl3v3Dy1pr@W"; 48 private static final String KEY_CIPHER = "tn#mpOl3v3Dy1pr@W";
50 49
51 // Timeout constants 50 // Timeout constants
...@@ -137,19 +136,14 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -137,19 +136,14 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
137 136
138 public static synchronized WarplyDBHelper getInstance(Context context) { 137 public static synchronized WarplyDBHelper getInstance(Context context) {
139 if (mDBHelperInstance == null) { 138 if (mDBHelperInstance == null) {
140 -// SQLiteDatabase.loadLibs(context); //old implementation 139 + ReLinker.loadLibrary(context, "sqlcipher");
141 - SQLiteDatabase.loadLibs(context, libraries -> {
142 - for (String library : libraries) {
143 - ReLinker.loadLibrary(context, library);
144 - }
145 - });
146 mDBHelperInstance = new WarplyDBHelper(context); 140 mDBHelperInstance = new WarplyDBHelper(context);
147 } 141 }
148 return mDBHelperInstance; 142 return mDBHelperInstance;
149 } 143 }
150 144
151 private WarplyDBHelper(Context context) { 145 private WarplyDBHelper(Context context) {
152 - super(context, DB_NAME, null, DB_VERSION); 146 + super(context, DB_NAME, KEY_CIPHER, null, DB_VERSION, 0, null, null, false);
153 State tempDatabaseState = getDatabaseState(context, DB_NAME); 147 State tempDatabaseState = getDatabaseState(context, DB_NAME);
154 if (tempDatabaseState.equals(State.UNENCRYPTED)) { 148 if (tempDatabaseState.equals(State.UNENCRYPTED)) {
155 encrypt(context, context.getDatabasePath(DB_NAME), KEY_CIPHER.getBytes()); 149 encrypt(context, context.getDatabasePath(DB_NAME), KEY_CIPHER.getBytes());
...@@ -164,7 +158,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -164,7 +158,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
164 if (mDb == null || !mDb.isOpen()) { 158 if (mDb == null || !mDb.isOpen()) {
165 try { 159 try {
166 // Submit task to executor and get future 160 // Submit task to executor and get future
167 - Future<SQLiteDatabase> future = dbExecutor.submit(() -> getWritableDatabase(KEY_CIPHER)); 161 + Future<SQLiteDatabase> future = dbExecutor.submit(() -> getWritableDatabase());
168 162
169 // Wait for result with timeout 163 // Wait for result with timeout
170 mDb = future.get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS); 164 mDb = future.get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
...@@ -192,7 +186,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -192,7 +186,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
192 if (mDb == null || !mDb.isOpen()) { 186 if (mDb == null || !mDb.isOpen()) {
193 try { 187 try {
194 // Submit task to executor and get future 188 // Submit task to executor and get future
195 - Future<SQLiteDatabase> future = dbExecutor.submit(() -> getReadableDatabase(KEY_CIPHER)); 189 + Future<SQLiteDatabase> future = dbExecutor.submit(() -> getReadableDatabase());
196 190
197 // Wait for result with timeout 191 // Wait for result with timeout
198 mDb = future.get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS); 192 mDb = future.get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
...@@ -214,7 +208,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -214,7 +208,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
214 208
215 private SQLiteDatabase getReadableDbInner() { 209 private SQLiteDatabase getReadableDbInner() {
216 if (mDb == null) 210 if (mDb == null)
217 - mDb = getReadableDatabase(KEY_CIPHER); 211 + mDb = getReadableDatabase();
218 return mDb; 212 return mDb;
219 } 213 }
220 214
...@@ -237,7 +231,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -237,7 +231,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
237 if (mDb == null || !mDb.isOpen()) { 231 if (mDb == null || !mDb.isOpen()) {
238 try { 232 try {
239 // Submit task to executor and get future 233 // Submit task to executor and get future
240 - Future<SQLiteDatabase> future = dbExecutor.submit(() -> getWritableDatabase(KEY_CIPHER)); 234 + Future<SQLiteDatabase> future = dbExecutor.submit(() -> getWritableDatabase());
241 235
242 // Wait for result with timeout 236 // Wait for result with timeout
243 mDb = future.get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS); 237 mDb = future.get(CONNECTION_TIMEOUT_MS, TimeUnit.MILLISECONDS);
...@@ -834,7 +828,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -834,7 +828,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
834 } 828 }
835 829
836 private State getDatabaseState(Context context, String dbName) { 830 private State getDatabaseState(Context context, String dbName) {
837 - SQLiteDatabase.loadLibs(context); 831 + ReLinker.loadLibrary(context, "sqlcipher");
838 832
839 return (getDatabaseState(context.getDatabasePath(dbName))); 833 return (getDatabaseState(context.getDatabasePath(dbName)));
840 } 834 }
...@@ -843,7 +837,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -843,7 +837,7 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
843 if (dbPath.exists()) { 837 if (dbPath.exists()) {
844 SQLiteDatabase db = null; 838 SQLiteDatabase db = null;
845 try { 839 try {
846 - db = SQLiteDatabase.openDatabase(dbPath.getAbsolutePath(), "", null, SQLiteDatabase.OPEN_READONLY); 840 + db = SQLiteDatabase.openDatabase(dbPath.getAbsolutePath(), "", null, SQLiteDatabase.OPEN_READONLY, null, null);
847 db.getVersion(); 841 db.getVersion();
848 842
849 return (State.UNENCRYPTED); 843 return (State.UNENCRYPTED);
...@@ -860,13 +854,13 @@ public class WarplyDBHelper extends SQLiteOpenHelper { ...@@ -860,13 +854,13 @@ public class WarplyDBHelper extends SQLiteOpenHelper {
860 } 854 }
861 855
862 private void encrypt(Context context, File originalFile, byte[] passphrase) { 856 private void encrypt(Context context, File originalFile, byte[] passphrase) {
863 - SQLiteDatabase.loadLibs(context); 857 + ReLinker.loadLibrary(context, "sqlcipher");
864 858
865 try { 859 try {
866 if (originalFile.exists()) { 860 if (originalFile.exists()) {
867 File newFile = File.createTempFile("sqlcipherutils", "tmp", context.getCacheDir()); 861 File newFile = File.createTempFile("sqlcipherutils", "tmp", context.getCacheDir());
868 SQLiteDatabase db = SQLiteDatabase.openDatabase(originalFile.getAbsolutePath(), 862 SQLiteDatabase db = SQLiteDatabase.openDatabase(originalFile.getAbsolutePath(),
869 - "", null, SQLiteDatabase.OPEN_READWRITE); 863 + "", null, SQLiteDatabase.OPEN_READWRITE, null, null);
870 int version = db.getVersion(); 864 int version = db.getVersion();
871 865
872 db.close(); 866 db.close();
......