@capacitor-community/sqlite 3.4.0-1 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +17 -0
  3. package/android/build.gradle +1 -1
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +127 -6
  5. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +94 -12
  6. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/BiometricListener.java +8 -0
  7. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/SqliteConfig.java +32 -0
  8. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsBiometric.java +123 -0
  9. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLCipher.java +7 -2
  10. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSecret.java +7 -2
  11. package/dist/esm/definitions.d.ts +21 -0
  12. package/dist/esm/definitions.js +55 -0
  13. package/dist/esm/definitions.js.map +1 -1
  14. package/dist/plugin.cjs.js +55 -0
  15. package/dist/plugin.cjs.js.map +1 -1
  16. package/dist/plugin.js +55 -0
  17. package/dist/plugin.js.map +1 -1
  18. package/ios/Plugin/BiometricIDAuthentication.swift +79 -0
  19. package/ios/Plugin/CapacitorSQLite.swift +144 -24
  20. package/ios/Plugin/CapacitorSQLitePlugin.swift +52 -9
  21. package/ios/Plugin/Database.swift +5 -2
  22. package/ios/Plugin/Extensions/Notification.Name.swift +6 -2
  23. package/ios/Plugin/Models/KeychainServices.swift +1 -1
  24. package/ios/Plugin/SqliteConfig.swift +3 -0
  25. package/ios/Plugin/Utils/UtilsSQLCipher.swift +5 -4
  26. package/ios/Plugin/Utils/UtilsSecret.swift +54 -22
  27. package/package.json +6 -6
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Quéau Jean Pierre
3
+ Copyright (c) 2022 Quéau Jean Pierre
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -28,6 +28,20 @@
28
28
 
29
29
  ## CAPACITOR 3 (Master)
30
30
 
31
+ 🚨 Since release 3.4.0-2 ->> 🚨
32
+
33
+ - iOS & Android only
34
+ Adding biometric FaceID/TouchID to secure the pass phrase in the Keychain/SharedPreferences stores. see:
35
+ [Biometric_Authentication](https://github.com/capacitor-community/sqlite/blob/master/docs/Biometric-Authentication.md)
36
+
37
+ - iOS only
38
+ Fix identical pass phrase stored in the Keychain for differents applications using the plugin by adding an application prefix to the Keychain account.
39
+ Before the account `"CapacitorSQLitePlugin"` was used and was the same for all applications.
40
+ Now by adding `iosKeychainPrefix: 'YOUR_APP_NAME'`in the `capacitor.config.ts` of your application,
41
+ the account will be `"YOUR_APP_NAME_CapacitorSQLitePlugin"`
42
+ If you were having a pass phrase stored, first modify the `capacitor.config.ts` and then run the command `isSecretStored` which will manage the upgrade of the Keychain account.
43
+ 🚨 Since release 3.4.0-2 <<- 🚨
44
+
31
45
  🚨 Since release 3.3.3-2 ->> 🚨
32
46
 
33
47
  - iOS only
@@ -240,6 +254,7 @@ No configuration required for this plugin
240
254
  | createNCConnection | ✅ | ✅ | ❌ | ❌ |
241
255
  | closeNCConnection | ✅ | ✅ | ❌ | ❌ |
242
256
  | isNCDatabase | ✅ | ✅ | ❌ | ❌ |
257
+ | transaction | ✅ | ✅ | ✅ | ✅ |
243
258
 
244
259
  ## Supported SQLite Types
245
260
 
@@ -267,6 +282,8 @@ No configuration required for this plugin
267
282
 
268
283
  - [Non_Conformed_Databases_Documentation](https://github.com/capacitor-community/sqlite/blob/master/docs/NonConformedDatabases.md)
269
284
 
285
+ - [Biometric_Authentication](https://github.com/capacitor-community/sqlite/blob/master/docs/Biometric-Authentication.md)
286
+
270
287
  ### Framework's Usage
271
288
 
272
289
  - [Ionic/Angular_Usage_Documentation](https://github.com/capacitor-community/sqlite/blob/master/docs/Ionic-Angular-Usage.md)
@@ -61,6 +61,6 @@ dependencies {
61
61
  implementation "androidx.sqlite:sqlite:2.1.0"
62
62
  //security library
63
63
  implementation "androidx.security:security-crypto:1.1.0-alpha03"
64
+ implementation "androidx.biometric:biometric:1.1.0"
64
65
  annotationProcessor 'androidx.room:room-compiler:2.2.5'
65
-
66
66
  }
@@ -4,14 +4,21 @@ import android.content.Context;
4
4
  import android.content.SharedPreferences;
5
5
  import android.text.TextUtils;
6
6
  import android.util.Log;
7
+ import android.widget.Toast;
8
+ import androidx.biometric.BiometricManager;
9
+ import androidx.biometric.BiometricPrompt;
7
10
  import androidx.security.crypto.EncryptedSharedPreferences;
8
11
  import androidx.security.crypto.MasterKey;
9
12
  import androidx.security.crypto.MasterKeys;
10
13
  import com.getcapacitor.JSArray;
11
14
  import com.getcapacitor.JSObject;
15
+ import com.getcapacitor.PluginCall;
16
+ import com.getcapacitor.community.database.sqlite.SQLite.BiometricListener;
12
17
  import com.getcapacitor.community.database.sqlite.SQLite.Database;
13
18
  import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.JsonSQLite;
14
19
  import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.UtilsJson;
20
+ import com.getcapacitor.community.database.sqlite.SQLite.SqliteConfig;
21
+ import com.getcapacitor.community.database.sqlite.SQLite.UtilsBiometric;
15
22
  import com.getcapacitor.community.database.sqlite.SQLite.UtilsFile;
16
23
  import com.getcapacitor.community.database.sqlite.SQLite.UtilsMigrate;
17
24
  import com.getcapacitor.community.database.sqlite.SQLite.UtilsNCDatabase;
@@ -19,15 +26,21 @@ import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLite;
19
26
  import com.getcapacitor.community.database.sqlite.SQLite.UtilsSecret;
20
27
  import java.io.File;
21
28
  import java.io.IOException;
29
+ import java.nio.charset.Charset;
30
+ import java.nio.charset.StandardCharsets;
22
31
  import java.security.GeneralSecurityException;
23
32
  import java.util.ArrayList;
24
33
  import java.util.Arrays;
25
34
  import java.util.Collections;
26
35
  import java.util.Dictionary;
27
36
  import java.util.Enumeration;
37
+ import java.util.HashMap;
28
38
  import java.util.HashSet;
29
39
  import java.util.Hashtable;
40
+ import java.util.Map;
30
41
  import java.util.Set;
42
+ import javax.crypto.BadPaddingException;
43
+ import javax.crypto.IllegalBlockSizeException;
31
44
  import org.json.JSONException;
32
45
  import org.json.JSONObject;
33
46
 
@@ -43,13 +56,86 @@ public class CapacitorSQLite {
43
56
  private UtilsNCDatabase uNCDatabase = new UtilsNCDatabase();
44
57
  private UtilsSecret uSecret;
45
58
  private SharedPreferences sharedPreferences;
46
-
47
- public CapacitorSQLite(Context context) throws Exception {
59
+ private MasterKey masterKeyAlias;
60
+ private BiometricManager biometricManager;
61
+ private SqliteConfig config;
62
+ private Boolean biometricAuth = false;
63
+ private String biometricTitle;
64
+ private String biometricSubTitle;
65
+ private int VALIDITY_DURATION = 1;
66
+ private RetHandler rHandler = new RetHandler();
67
+ private PluginCall call;
68
+
69
+ public CapacitorSQLite(Context context, SqliteConfig config) throws Exception {
48
70
  this.context = context;
71
+ this.call = call;
72
+ this.config = config;
73
+ this.biometricAuth = this.config.getBiometricAuth();
74
+ this.biometricTitle = this.config.getBiometricTitle();
75
+ this.biometricSubTitle = this.config.getBiometricSubTitle();
49
76
  try {
50
77
  // create or retrieve masterkey from Android keystore
51
78
  // it will be used to encrypt the passphrase for a database
52
- MasterKey masterKeyAlias = new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
79
+
80
+ if (biometricAuth) {
81
+ biometricManager = BiometricManager.from(this.context);
82
+ BiometricListener listener = new BiometricListener() {
83
+ @Override
84
+ public void onSuccess(BiometricPrompt.AuthenticationResult result) {
85
+ try {
86
+ masterKeyAlias =
87
+ new MasterKey.Builder(context)
88
+ .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
89
+ .setUserAuthenticationRequired(true, VALIDITY_DURATION)
90
+ .build();
91
+ setSharedPreferences();
92
+ notifyBiometricEvent(true, null);
93
+ return;
94
+ } catch (Exception e) {
95
+ String input = e.getMessage();
96
+ Log.e("MY_APP_TAG", input);
97
+ // Toast.makeText(context, input, Toast.LENGTH_LONG).show();
98
+ notifyBiometricEvent(false, input);
99
+ }
100
+ }
101
+
102
+ @Override
103
+ public void onFailed() {
104
+ String input = "Error in authenticating biometric";
105
+ Log.e("MY_APP_TAG", input);
106
+ // Toast.makeText(context, input, Toast.LENGTH_LONG).show();
107
+ notifyBiometricEvent(false, input);
108
+ }
109
+ };
110
+ UtilsBiometric uBiom = new UtilsBiometric(context, biometricManager, listener);
111
+ if (uBiom.checkBiometricIsAvailable()) {
112
+ uBiom.showBiometricDialog(this.biometricTitle, this.biometricSubTitle);
113
+ } else {
114
+ masterKeyAlias = new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
115
+ setSharedPreferences();
116
+ }
117
+ } else {
118
+ masterKeyAlias = new MasterKey.Builder(context).setKeyScheme(MasterKey.KeyScheme.AES256_GCM).build();
119
+ setSharedPreferences();
120
+ }
121
+ } catch (Exception e) {
122
+ throw new Exception(e.getMessage());
123
+ }
124
+ }
125
+
126
+ private void notifyBiometricEvent(Boolean ret, String msg) {
127
+ Map<String, Object> info = new HashMap<String, Object>() {
128
+ {
129
+ put("result", ret);
130
+ put("message", msg);
131
+ }
132
+ };
133
+ Log.v(TAG, "$$$$$ in notifyBiometricEvent " + info);
134
+ NotificationCenter.defaultCenter().postNotification("biometricResults", info);
135
+ }
136
+
137
+ private void setSharedPreferences() throws Exception {
138
+ try {
53
139
  // get instance of the EncryptedSharedPreferences class
54
140
  this.sharedPreferences =
55
141
  EncryptedSharedPreferences.create(
@@ -107,12 +193,47 @@ public class CapacitorSQLite {
107
193
  * @param oldPassphrase
108
194
  * @throws Exception
109
195
  */
110
- public void changeEncryptionSecret(String passphrase, String oldPassphrase) throws Exception {
196
+ public void changeEncryptionSecret(PluginCall call, String passphrase, String oldPassphrase) throws Exception {
197
+ this.call = call;
111
198
  try {
112
199
  // close all connections
113
200
  closeAllConnections();
114
- // change encryption secret
115
- uSecret.changeEncryptionSecret(passphrase, oldPassphrase);
201
+ if (biometricAuth) {
202
+ BiometricListener listener = new BiometricListener() {
203
+ @Override
204
+ public void onSuccess(BiometricPrompt.AuthenticationResult result) {
205
+ try {
206
+ // change encryption secret
207
+ uSecret.changeEncryptionSecret(passphrase, oldPassphrase);
208
+ rHandler.retResult(call, null, null);
209
+ return;
210
+ } catch (Exception e) {
211
+ String input = e.getMessage();
212
+ Log.e("MY_APP_TAG", input);
213
+ Toast.makeText(context, input, Toast.LENGTH_LONG).show();
214
+ rHandler.retResult(call, null, e.getMessage());
215
+ }
216
+ }
217
+
218
+ @Override
219
+ public void onFailed() {
220
+ String input = "Error in authenticating biometric";
221
+ Log.e("MY_APP_TAG", input);
222
+ Toast.makeText(context, input, Toast.LENGTH_LONG).show();
223
+ rHandler.retResult(call, null, input);
224
+ }
225
+ };
226
+
227
+ UtilsBiometric uBiom = new UtilsBiometric(context, biometricManager, listener);
228
+ if (uBiom.checkBiometricIsAvailable()) {
229
+ uBiom.showBiometricDialog(biometricTitle, biometricSubTitle);
230
+ } else {
231
+ throw new Exception("Biometric features are currently unavailable.");
232
+ }
233
+ } else {
234
+ // change encryption secret
235
+ uSecret.changeEncryptionSecret(passphrase, oldPassphrase);
236
+ }
116
237
  } catch (Exception e) {
117
238
  throw new Exception(e.getMessage());
118
239
  }
@@ -10,9 +10,11 @@ import com.getcapacitor.PluginMethod;
10
10
  import com.getcapacitor.annotation.CapacitorPlugin;
11
11
  import com.getcapacitor.community.database.sqlite.SQLite.Database;
12
12
  import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.JsonSQLite;
13
+ import com.getcapacitor.community.database.sqlite.SQLite.SqliteConfig;
13
14
  import java.util.Dictionary;
14
15
  import java.util.Hashtable;
15
16
  import org.json.JSONArray;
17
+ import org.json.JSONException;
16
18
  import org.json.JSONObject;
17
19
 
18
20
  @CapacitorPlugin(name = "CapacitorSQLite")
@@ -20,9 +22,12 @@ public class CapacitorSQLitePlugin extends Plugin {
20
22
 
21
23
  private static final String TAG = CapacitorSQLitePlugin.class.getName();
22
24
  private Context context;
25
+ private SqliteConfig config;
23
26
  private CapacitorSQLite implementation;
24
27
  private Dictionary<String, Dictionary<Integer, JSONObject>> versionUpgrades = new Hashtable<>();
25
28
  private RetHandler rHandler = new RetHandler();
29
+ private String passphrase = null;
30
+ private String oldpassphrase = null;
26
31
 
27
32
  /**
28
33
  * Load Method
@@ -31,8 +36,12 @@ public class CapacitorSQLitePlugin extends Plugin {
31
36
  public void load() {
32
37
  context = getContext();
33
38
  try {
34
- implementation = new CapacitorSQLite(context);
39
+ config = getSqliteConfig();
35
40
  AddObserversToNotificationCenter();
41
+ implementation = new CapacitorSQLite(context, config);
42
+ } catch (JSONException e) {
43
+ implementation = null;
44
+ Log.e(TAG, "CapacitorSQLitePlugin: " + e.getMessage());
36
45
  } catch (Exception e) {
37
46
  implementation = null;
38
47
  Log.e(TAG, "CapacitorSQLitePlugin: " + e.getMessage());
@@ -42,6 +51,7 @@ public class CapacitorSQLitePlugin extends Plugin {
42
51
  /**
43
52
  * Echo Method
44
53
  * test the plugin
54
+ *
45
55
  * @param call
46
56
  */
47
57
  @PluginMethod
@@ -59,6 +69,7 @@ public class CapacitorSQLitePlugin extends Plugin {
59
69
  /**
60
70
  * IsSecretStored
61
71
  * Check if a secret has been stored
72
+ *
62
73
  * @param call
63
74
  */
64
75
  @PluginMethod
@@ -77,6 +88,7 @@ public class CapacitorSQLitePlugin extends Plugin {
77
88
  /**
78
89
  * SetEncryptionSecret
79
90
  * set a passphrase secret for a database
91
+ *
80
92
  * @param call
81
93
  */
82
94
  @PluginMethod
@@ -103,33 +115,40 @@ public class CapacitorSQLitePlugin extends Plugin {
103
115
  * ChangeEncryptionSecret
104
116
  * change a passphrase secret for a database
105
117
  * with a new passphrase
118
+ *
106
119
  * @param call
107
120
  */
108
121
  @PluginMethod
109
122
  public void changeEncryptionSecret(PluginCall call) {
110
- String passphrase = null;
111
123
  if (!call.getData().has("passphrase")) {
112
124
  String msg = "SetEncryptionSecret: Must provide a passphrase";
113
125
  rHandler.retResult(call, null, msg);
114
126
  return;
115
127
  }
116
128
  passphrase = call.getString("passphrase");
117
- String oldpassphrase = null;
129
+
118
130
  if (!call.getData().has("oldpassphrase")) {
119
131
  String msg = "SetEncryptionSecret: Must provide a oldpassphrase";
120
132
  rHandler.retResult(call, null, msg);
121
133
  return;
122
134
  }
123
135
  oldpassphrase = call.getString("oldpassphrase");
124
- try {
125
- implementation.changeEncryptionSecret(passphrase, oldpassphrase);
126
- rHandler.retResult(call, null, null);
127
- return;
128
- } catch (Exception e) {
129
- String msg = "ChangeEncryptionSecret: " + e.getMessage();
130
- rHandler.retResult(call, null, msg);
131
- return;
132
- }
136
+ getActivity()
137
+ .runOnUiThread(
138
+ new Runnable() {
139
+ @Override
140
+ public void run() {
141
+ try {
142
+ implementation.changeEncryptionSecret(call, passphrase, oldpassphrase);
143
+ return;
144
+ } catch (Exception e) {
145
+ String msg = "ChangeEncryptionSecret: " + e.getMessage();
146
+ rHandler.retResult(call, null, msg);
147
+ return;
148
+ }
149
+ }
150
+ }
151
+ );
133
152
  }
134
153
 
135
154
  @PluginMethod
@@ -162,6 +181,7 @@ public class CapacitorSQLitePlugin extends Plugin {
162
181
  /**
163
182
  * CreateNCConnection Method
164
183
  * Create a non-conformed connection to a database
184
+ *
165
185
  * @param call
166
186
  */
167
187
  @PluginMethod
@@ -189,6 +209,7 @@ public class CapacitorSQLitePlugin extends Plugin {
189
209
  /**
190
210
  * CreateConnection Method
191
211
  * Create a connection to a database
212
+ *
192
213
  * @param call
193
214
  */
194
215
  @PluginMethod
@@ -204,6 +225,7 @@ public class CapacitorSQLitePlugin extends Plugin {
204
225
  }
205
226
  dbName = call.getString("database");
206
227
  dbVersion = call.getInt("version", 1);
228
+
207
229
  boolean encrypted = call.getBoolean("encrypted", false);
208
230
  if (encrypted) {
209
231
  inMode = call.getString("mode", "no-encryption");
@@ -234,6 +256,7 @@ public class CapacitorSQLitePlugin extends Plugin {
234
256
  /**
235
257
  * Open Method
236
258
  * Open a database
259
+ *
237
260
  * @param call
238
261
  */
239
262
  @PluginMethod
@@ -258,6 +281,7 @@ public class CapacitorSQLitePlugin extends Plugin {
258
281
  /**
259
282
  * Close Method
260
283
  * Close a Database
284
+ *
261
285
  * @param call
262
286
  */
263
287
  @PluginMethod
@@ -282,6 +306,7 @@ public class CapacitorSQLitePlugin extends Plugin {
282
306
  /**
283
307
  * GetUrl Method
284
308
  * Get a database Url
309
+ *
285
310
  * @param call
286
311
  */
287
312
  @PluginMethod
@@ -306,6 +331,7 @@ public class CapacitorSQLitePlugin extends Plugin {
306
331
  /**
307
332
  * GetVersion Method
308
333
  * Get a database Version
334
+ *
309
335
  * @param call
310
336
  */
311
337
  @PluginMethod
@@ -330,6 +356,7 @@ public class CapacitorSQLitePlugin extends Plugin {
330
356
  /**
331
357
  * CloseNCConnection Method
332
358
  * Close a non-conformed database connection
359
+ *
333
360
  * @param call
334
361
  */
335
362
  @PluginMethod
@@ -354,6 +381,7 @@ public class CapacitorSQLitePlugin extends Plugin {
354
381
  /**
355
382
  * CloseConnection Method
356
383
  * Close the connection to a database
384
+ *
357
385
  * @param call
358
386
  */
359
387
  @PluginMethod
@@ -378,6 +406,7 @@ public class CapacitorSQLitePlugin extends Plugin {
378
406
  /**
379
407
  * CheckConnectionsConsistency Method
380
408
  * Check the connections consistency JS <=> Native
409
+ *
381
410
  * @param call
382
411
  */
383
412
  @PluginMethod
@@ -402,6 +431,7 @@ public class CapacitorSQLitePlugin extends Plugin {
402
431
  /**
403
432
  * IsDatabase Method
404
433
  * Check if the database file exists
434
+ *
405
435
  * @param call
406
436
  */
407
437
  @PluginMethod
@@ -425,6 +455,7 @@ public class CapacitorSQLitePlugin extends Plugin {
425
455
  /**
426
456
  * IsDatabase Method
427
457
  * Check if the database file exists
458
+ *
428
459
  * @param call
429
460
  */
430
461
  @PluginMethod
@@ -448,6 +479,7 @@ public class CapacitorSQLitePlugin extends Plugin {
448
479
  /**
449
480
  * IsTableExists Method
450
481
  * Check if a table exists in a database
482
+ *
451
483
  * @param call
452
484
  */
453
485
  @PluginMethod
@@ -575,6 +607,7 @@ public class CapacitorSQLitePlugin extends Plugin {
575
607
  /**
576
608
  * Execute Method
577
609
  * Execute SQL statements provided in a String
610
+ *
578
611
  * @param call
579
612
  */
580
613
  @PluginMethod
@@ -609,6 +642,7 @@ public class CapacitorSQLitePlugin extends Plugin {
609
642
  /**
610
643
  * ExecuteSet Method
611
644
  * Execute a Set of raw sql statement
645
+ *
612
646
  * @param call
613
647
  * @throws Exception
614
648
  */
@@ -660,6 +694,7 @@ public class CapacitorSQLitePlugin extends Plugin {
660
694
  /**
661
695
  * Run method
662
696
  * Execute a raw sql statement
697
+ *
663
698
  * @param call
664
699
  */
665
700
  @PluginMethod
@@ -701,6 +736,7 @@ public class CapacitorSQLitePlugin extends Plugin {
701
736
  /**
702
737
  * Query Method
703
738
  * Execute an sql query
739
+ *
704
740
  * @param call
705
741
  */
706
742
  @PluginMethod
@@ -737,6 +773,7 @@ public class CapacitorSQLitePlugin extends Plugin {
737
773
  /**
738
774
  * IsDBExists Method
739
775
  * check if the database exists on the database folder
776
+ *
740
777
  * @param call
741
778
  */
742
779
  @PluginMethod
@@ -762,6 +799,7 @@ public class CapacitorSQLitePlugin extends Plugin {
762
799
  /**
763
800
  * IsDBOpen Method
764
801
  * check if the database is opened
802
+ *
765
803
  * @param call
766
804
  */
767
805
  @PluginMethod
@@ -786,6 +824,7 @@ public class CapacitorSQLitePlugin extends Plugin {
786
824
  /**
787
825
  * DeleteDatabase Method
788
826
  * delete a database from the database folder
827
+ *
789
828
  * @param call
790
829
  */
791
830
  @PluginMethod
@@ -810,6 +849,7 @@ public class CapacitorSQLitePlugin extends Plugin {
810
849
  /**
811
850
  * CreateSyncTable Method
812
851
  * Create the synchronization table
852
+ *
813
853
  * @param call
814
854
  */
815
855
  @PluginMethod
@@ -836,6 +876,7 @@ public class CapacitorSQLitePlugin extends Plugin {
836
876
  /**
837
877
  * SetSyncDate Method
838
878
  * set the synchronization date
879
+ *
839
880
  * @param call
840
881
  */
841
882
  @PluginMethod
@@ -867,6 +908,7 @@ public class CapacitorSQLitePlugin extends Plugin {
867
908
  /**
868
909
  * GetSyncDate Method
869
910
  * Get the synchronization date
911
+ *
870
912
  * @param call
871
913
  */
872
914
  @PluginMethod
@@ -893,6 +935,7 @@ public class CapacitorSQLitePlugin extends Plugin {
893
935
  /**
894
936
  * AddUpgradeStatement Method
895
937
  * Define an upgrade object when updating to a new version
938
+ *
896
939
  * @param call
897
940
  */
898
941
  @PluginMethod
@@ -925,6 +968,7 @@ public class CapacitorSQLitePlugin extends Plugin {
925
968
  /**
926
969
  * IsJsonValid
927
970
  * Check the validity of a given Json object
971
+ *
928
972
  * @param call
929
973
  */
930
974
  @PluginMethod
@@ -949,6 +993,7 @@ public class CapacitorSQLitePlugin extends Plugin {
949
993
  /**
950
994
  * ImportFromJson Method
951
995
  * Import from a given Json object
996
+ *
952
997
  * @param call
953
998
  */
954
999
  @PluginMethod
@@ -975,6 +1020,7 @@ public class CapacitorSQLitePlugin extends Plugin {
975
1020
  /**
976
1021
  * ExportToJson Method
977
1022
  * Export the database to Json Object
1023
+ *
978
1024
  * @param call
979
1025
  */
980
1026
  @PluginMethod
@@ -1014,6 +1060,7 @@ public class CapacitorSQLitePlugin extends Plugin {
1014
1060
  /**
1015
1061
  * CopyFromAssets
1016
1062
  * copy all databases from public/assets/databases to application folder
1063
+ *
1017
1064
  * @param call
1018
1065
  */
1019
1066
  @PluginMethod
@@ -1060,5 +1107,40 @@ public class CapacitorSQLitePlugin extends Plugin {
1060
1107
  }
1061
1108
  }
1062
1109
  );
1110
+ NotificationCenter
1111
+ .defaultCenter()
1112
+ .addMethodForNotification(
1113
+ "biometricResults",
1114
+ new MyRunnable() {
1115
+ @Override
1116
+ public void run() {
1117
+ JSObject data = new JSObject();
1118
+ data.put("result", this.getInfo().get("result"));
1119
+ data.put("message", this.getInfo().get("message"));
1120
+ notifyListeners("sqliteBiometricEvent", data);
1121
+ return;
1122
+ }
1123
+ }
1124
+ );
1125
+ }
1126
+
1127
+ private SqliteConfig getSqliteConfig() throws JSONException {
1128
+ SqliteConfig config = new SqliteConfig();
1129
+ JSONObject androidBiometric = getConfig().getObject("androidBiometric");
1130
+ if (androidBiometric != null) {
1131
+ Boolean biometricAuth = androidBiometric.has("biometricAuth")
1132
+ ? androidBiometric.getBoolean("biometricAuth")
1133
+ : config.getBiometricAuth();
1134
+ config.setBiometricAuth(biometricAuth);
1135
+ String biometricTitle = androidBiometric.has("biometricTitle")
1136
+ ? androidBiometric.getString("biometricTitle")
1137
+ : config.getBiometricTitle();
1138
+ config.setBiometricTitle(biometricTitle);
1139
+ String biometricSubTitle = androidBiometric.has("biometricSubTitle")
1140
+ ? androidBiometric.getString("biometricSubTitle")
1141
+ : config.getBiometricSubTitle();
1142
+ config.setBiometricSubTitle(biometricSubTitle);
1143
+ }
1144
+ return config;
1063
1145
  }
1064
1146
  }
@@ -0,0 +1,8 @@
1
+ package com.getcapacitor.community.database.sqlite.SQLite;
2
+
3
+ import androidx.biometric.BiometricPrompt;
4
+
5
+ public interface BiometricListener {
6
+ void onSuccess(BiometricPrompt.AuthenticationResult result);
7
+ void onFailed();
8
+ }
@@ -0,0 +1,32 @@
1
+ package com.getcapacitor.community.database.sqlite.SQLite;
2
+
3
+ public class SqliteConfig {
4
+
5
+ private boolean biometricAuth = false;
6
+ private String biometricTitle = "Biometric login for capacitor sqlite";
7
+ private String biometricSubTitle = "Log in using your biometric";
8
+
9
+ public boolean getBiometricAuth() {
10
+ return biometricAuth;
11
+ }
12
+
13
+ public void setBiometricAuth(boolean biometricAuth) {
14
+ this.biometricAuth = biometricAuth;
15
+ }
16
+
17
+ public String getBiometricTitle() {
18
+ return biometricTitle;
19
+ }
20
+
21
+ public void setBiometricTitle(String biometricTitle) {
22
+ this.biometricTitle = biometricTitle;
23
+ }
24
+
25
+ public String getBiometricSubTitle() {
26
+ return biometricSubTitle;
27
+ }
28
+
29
+ public void setBiometricSubTitle(String biometricSubTitle) {
30
+ this.biometricSubTitle = biometricSubTitle;
31
+ }
32
+ }